Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheet): parseValue handle number (#4049)

Dushusir59b95fa23f43
diff --git a/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts b/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts
index f2b9a280f2..924172fa6e 100644
--- a/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts
+++ b/packages/sheets-ui/src/controllers/editor/__tests__/end-edit.controller.spec.ts
@@ -600,6 +600,10 @@ describe('Test EndEditController', () => {
it('should handle escaped quotes in strings', () => {
expect(normalizeStringByLexer('="He said, ""Hello, .5!"""')).toBe('="He said, ""Hello, .5!"""');
});
+ it('Illegal strings should not be modified', () => {
+ expect(normalizeStringByLexer('=SUM(11, 2 2, 33)')).toBe('=SUM(11, 2 2, 33)');
+ expect(normalizeStringByLexer('=SUM(11, 123 123, 33)')).toBe('=SUM(11, 123 123, 33)');
+ });
});
});
});
diff --git a/packages/sheets-ui/src/controllers/utils/char-tools.ts b/packages/sheets-ui/src/controllers/utils/char-tools.ts
index d932f80abe..ad6211e63d 100644
--- a/packages/sheets-ui/src/controllers/utils/char-tools.ts
+++ b/packages/sheets-ui/src/controllers/utils/char-tools.ts
@@ -145,7 +145,7 @@ function normalizeFormulaString(str: string, normalStr: string, lexerTreeBuilder
}
// Entering =.07/0.1 in a cell will automatically convert to =0.07/0.1
// Entering =1.0+2.00 in a cell will automatically convert to =1+2
- else if (typeof parsedValue.v === 'number') {
+ else if (typeof parsedValue.v === 'number' && (parsedValue.z === undefined || !numfmt.isDate(parsedValue.z))) {
const v = `${parsedValue.v}`;
const startIndex = node.startIndex + totalOffset + 1;
const endIndex = node.endIndex + totalOffset + 2;