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(numfmt): fix the issue where increasing/decreasing decimal places could not be applied when the cell number format was General (#5881)
wpxp123456794983f9a874
diff --git a/packages/sheets-numfmt/src/commands/commands/add-decimal.command.ts b/packages/sheets-numfmt/src/commands/commands/add-decimal.command.tsindex f3d095f491..2efb556f88 100644--- a/packages/sheets-numfmt/src/commands/commands/add-decimal.command.ts+++ b/packages/sheets-numfmt/src/commands/commands/add-decimal.command.ts@@ -15,8 +15,9 @@*/import type { IAccessor, ICommand } from '@univerjs/core';+import type { INumfmtItemWithCache } from '@univerjs/sheets';import type { ISetNumfmtCommandParams } from './set-numfmt.command';-import { CellValueType, CommandType, ICommandService, IUniverInstanceService, Range } from '@univerjs/core';+import { CellValueType, CommandType, ICommandService, isDefaultFormat, IUniverInstanceService, Range } from '@univerjs/core';import { getSheetCommandTarget, INumfmtService, SheetsSelectionsService } from '@univerjs/sheets';import { getDecimalFromPattern, setPatternDecimal } from '../../utils/decimal';import { SetNumfmtCommand } from './set-numfmt.command';@@ -68,16 +69,16 @@ export const AddDecimalCommand: ICommand = {selections.forEach((selection) => {Range.foreach(selection.range, (row, col) => {const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);- if (!numfmtValue) {+ if (isDefaultFormat(numfmtValue?.pattern)) {values.push({row,col,pattern: defaultPattern,});} else {- const decimals = getDecimalFromPattern(numfmtValue.pattern);- const pattern = setPatternDecimal(numfmtValue.pattern, decimals + 1);- pattern !== numfmtValue.pattern &&+ const decimals = getDecimalFromPattern((numfmtValue as INumfmtItemWithCache).pattern);+ const pattern = setPatternDecimal((numfmtValue as INumfmtItemWithCache).pattern, decimals + 1);+ pattern !== (numfmtValue as INumfmtItemWithCache).pattern &&values.push({row,col,diff --git a/packages/sheets-numfmt/src/commands/commands/subtract-decimal.command.ts b/packages/sheets-numfmt/src/commands/commands/subtract-decimal.command.tsindex 87cd743e24..f06c44421b 100644--- a/packages/sheets-numfmt/src/commands/commands/subtract-decimal.command.ts+++ b/packages/sheets-numfmt/src/commands/commands/subtract-decimal.command.ts@@ -15,8 +15,9 @@*/import type { IAccessor, ICommand } from '@univerjs/core';+import type { INumfmtItemWithCache } from '@univerjs/sheets';import type { ISetNumfmtCommandParams } from './set-numfmt.command';-import { CellValueType, CommandType, ICommandService, IUniverInstanceService, Range } from '@univerjs/core';+import { CellValueType, CommandType, ICommandService, isDefaultFormat, IUniverInstanceService, Range } from '@univerjs/core';import { getSheetCommandTarget, INumfmtService, SheetsSelectionsService } from '@univerjs/sheets';import { getDecimalFromPattern, setPatternDecimal } from '../../utils/decimal';import { SetNumfmtCommand } from './set-numfmt.command';@@ -70,18 +71,18 @@ export const SubtractDecimalCommand: ICommand = {selections.forEach((selection) => {Range.foreach(selection.range, (row, col) => {const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);- if (!numfmtValue) {+ if (isDefaultFormat(numfmtValue?.pattern)) {values.push({row,col,pattern: defaultPattern,});} else {- const decimals = getDecimalFromPattern(numfmtValue.pattern);+ const decimals = getDecimalFromPattern((numfmtValue as INumfmtItemWithCache).pattern);values.push({row,col,- pattern: setPatternDecimal(numfmtValue.pattern, decimals - 1),+ pattern: setPatternDecimal((numfmtValue as INumfmtItemWithCache).pattern, decimals - 1),});}});