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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(formula): fix bug in judging whether the value is in number format (#4493)
wpxp1234565d0b3979ff03
diff --git a/packages/engine-formula/src/engine/utils/numfmt-kit.ts b/packages/engine-formula/src/engine/utils/numfmt-kit.tsindex cf230a33fe..00fb48c5fe 100644--- a/packages/engine-formula/src/engine/utils/numfmt-kit.ts+++ b/packages/engine-formula/src/engine/utils/numfmt-kit.ts@@ -355,19 +355,19 @@ export function stringIsNumberPattern(input: string) {const numberPattern = numfmt.parseNumber(_input);- if (numberPattern) {+ if (numberPattern && numberPattern.z) {return setNumberPatternCache(_input, numberPattern.v as number, numberPattern.z as string);}const datePattern = numfmt.parseDate(_input);- if (datePattern) {+ if (datePattern && datePattern.z) {return setNumberPatternCache(_input, datePattern.v as number, datePattern.z as string);}const timePattern = numfmt.parseTime(_input);- if (timePattern) {+ if (timePattern && timePattern.z) {return setNumberPatternCache(_input, timePattern.v as number, timePattern.z as string);}diff --git a/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts b/packages/engine-formula/src/functions/__tests__/nested-functions.spec.tsindex 3217350b23..c449b6276f 100644--- a/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts+++ b/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts@@ -55,6 +55,7 @@ import { Min } from '../statistical/min';import { Concatenate } from '../text/concatenate';import { FUNCTION_NAMES_TEXT } from '../text/function-names';import { Len } from '../text/len';+import { Text } from '../text/text';import { createFunctionTestBed, getObjectValue } from './create-function-test-bed';const getFunctionsTestWorkbookData = (): IWorkbookData => {@@ -393,7 +394,8 @@ describe('Test nested functions', () => {new Len(FUNCTION_NAMES_TEXT.LEN),new Divided(FUNCTION_NAMES_META.DIVIDED),new Product(FUNCTION_NAMES_MATH.PRODUCT),- new Fact(FUNCTION_NAMES_MATH.FACT)+ new Fact(FUNCTION_NAMES_MATH.FACT),+ new Text(FUNCTION_NAMES_TEXT.TEXT));calculate = (formula: string) => {@@ -516,5 +518,12 @@ describe('Test nested functions', () => {[3628800],]);});++ it('Text formula test', () => {+ const result = calculate('=TEXT(1234, "000000")');+ expect(result).toStrictEqual([+ ['001234'],+ ]);+ });});});