Posted 1 April 2025, 1:32 pm EST - Updated 1 April 2025, 1:37 pm EST
Hello erveryone,
I’m trying to insert a value into a cell, but the value starts with “-”, so the formula modal opens
But I need that value to be a text
Example
Forums Home / Spread / SpreadJS
Posted by: pedro.moraes on 1 April 2025, 1:32 pm EST
Posted 1 April 2025, 1:32 pm EST - Updated 1 April 2025, 1:37 pm EST
Hello erveryone,
I’m trying to insert a value into a cell, but the value starts with “-”, so the formula modal opens
But I need that value to be a text
Example
Posted 2 April 2025, 3:54 am EST - Updated 2 April 2025, 4:00 am EST
Hi,
We can replicate the behavior you mentioned, and the same behavior can be observed in Microsoft Excel, too. To overcome this behavior, you can try the following:
Prefix the text with an apostrophe ': Instead of writing -T, write '-T.
Apply the @ string formatter as the edit changes in the Spreadsheet cells. Please refer to the code snippet below that demonstrates this approach:
spread.bind(spreadNS.Events.EditChange, function (sender, args) {
if (
args.editingText &&
args.editingText.startsWith("-") &&
args.sheet.getFormatter(args.row, args.col) != "@"
)
args.sheet.setFormatter(args.row, args.col, "@");
if (
!isNaN(args.editingText) &&
args.sheet.getFormatter(args.row, args.col) == "@"
)
args.sheet.setFormatter(args.row, args.col, null);
});
You can further refer to the attached sample that uses the above code snippet and handles the values starting with - (see below).
Please feel free to reach out if you encounter any further issues or require additional guidance.
Regards,
Ankit