Skip to content

Commit

Permalink
fix(formula): fix bug in judging whether the value is in number format (
Browse files Browse the repository at this point in the history
#4493)

Co-authored-by: wpxp123456 <Wpxp1223456>
  • Loading branch information
wpxp123456 authored Jan 16, 2025
1 parent 99b2600 commit 5d0b397
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/engine-formula/src/engine/utils/numfmt-kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -516,5 +518,12 @@ describe('Test nested functions', () => {
[3628800],
]);
});

it('Text formula test', () => {
const result = calculate('=TEXT(1234, "000000")');
expect(result).toStrictEqual([
['001234'],
]);
});
});
});

0 comments on commit 5d0b397

Please sign in to comment.