Posted 13 September 2022, 8:47 pm EST
Hi,
This is expected because the cell format can be different from the editmode formatter which is why it is not recommended to change the edit mode formatter. Excel also does the same. We are sorry for the inconvenience.
If you want to show the edit mode formatter the same as the cell formatter. YOu use the following workaround.
Of course, there are some other way to achieve the customer goal, but a little bit "hack", please consider whether provided to the customer.
var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 2 });
var sheet = spread.getActiveSheet();
var newForm = GC.Spread.Sheets.CellTypes.Text.prototype.setEditorValue;
var oldCmd = GC.Spread.Sheets.Commands.editCell.execute;
GC.Spread.Sheets.Commands.editCell.execute = function (context, options, isUndo) {
var sheet = context.getSheetFromName(options.sheetName);
var formatter = sheet.getFormatter(options.row, options.col);
if (options.editingFormatter && formatter) {
options.editingFormatter = new GC.Spread.Formatter.GeneralFormatter(formatter);
}
return oldCmd.apply(this, arguments);
}
GC.Spread.Sheets.CellTypes.Text.prototype.setEditorValue = function (
editor,
value,
context
) {
var sheet = context.sheet,
row = context.row,
column = context.col;
var cellValue = sheet.getValue(row, column);
var formatter = sheet.getFormatter(row, column);
if (cellValue && formatter) {
value = new GC.Spread.Formatter.GeneralFormatter(formatter).format(cellValue);
newForm.call(this, editor, value, context);
} else {
newForm.apply(this, arguments);
}
};
initSpread(spread);
function initSpread(spread) {
var sheet = spread.getActiveSheet();
sheet.setValue(0, 0, new Date(2020, 3, 31, 5, 6, 2, 1));
sheet.setFormatter(0, 0, "dd-mm-yyyy");
sheet.setColumnWidth(0, 150);
sheet.setValue(1, 0, new Date(2020, 3, 31, 5, 6, 2, 1));
sheet.setFormatter(1, 0, "dd~mmm~yyyy");
sheet.resumePaint();
}
Regards,
Avinash