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
feat(numfmt): refactor the numfmt model (#1945)
Gpound.liu18401663906e
diff --git a/examples/src/data/sheets/demo/default-workbook-data-demo.ts b/examples/src/data/sheets/demo/default-workbook-data-demo.tsindex a94640bb28..cd5748d503 100644--- a/examples/src/data/sheets/demo/default-workbook-data-demo.ts+++ b/examples/src/data/sheets/demo/default-workbook-data-demo.ts@@ -13958,6 +13958,21 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {v: 'A Schedule of Items',},},+ 1: {+ 0: {+ s: {+ n: {+ pattern: 'yyyy-mm-dd;@',+ },+ },+ v: 1,+ },+ },+ 2: {+ 0: {+ f: '=A2',+ },+ },5: {5: {s: 'uJSelZ11',diff --git a/packages/core/src/types/interfaces/__tests__/i-cell-data.spec.ts b/packages/core/src/types/interfaces/__tests__/i-cell-data.spec.tsindex 2b87b547fa..d77b8581d1 100644--- a/packages/core/src/types/interfaces/__tests__/i-cell-data.spec.ts+++ b/packages/core/src/types/interfaces/__tests__/i-cell-data.spec.ts@@ -16,10 +16,54 @@import { describe, expect, it } from 'vitest';-import { isCellV, isICellData } from '../i-cell-data';+import { isCellV, isICellData, isNullCell } from '../i-cell-data';++const DOCUMENT_DATA = {+ id: 'd',+ body: {+ dataStream: 'No.2824163\r\n',+ textRuns: [+ {+ st: 0,+ ed: 2,+ ts: {+ cl: {+ rgb: '#000',+ },+ fs: 20,+ },+ },+ {+ st: 3,+ ed: 10,+ ts: {+ cl: {+ rgb: 'rgb(255, 0, 0)',+ },+ fs: 20,+ },+ },+ ],+ paragraphs: [+ {+ startIndex: 10,+ },+ ],+ },+ documentStyle: {+ pageSize: {+ width: Number.POSITIVE_INFINITY,+ height: Number.POSITIVE_INFINITY,+ },+ marginTop: 0,+ marginBottom: 0,+ marginRight: 2,+ marginLeft: 2,+ },+};describe('Test cell data', () => {- it('function isICellData', () => {+ it('Function isICellData', () => {expect(isICellData({ s: '1' })).toBeTruthy();expect(isICellData({ p: { id: '1' } })).toBeTruthy();expect(isICellData({ v: '1' })).toBeTruthy();@@ -33,7 +77,7 @@ describe('Test cell data', () => {expect(isICellData({})).toBeFalsy();});- it('function isCellV', () => {+ it('Function isCellV', () => {expect(isCellV('1')).toBeTruthy();expect(isCellV(1)).toBeTruthy();expect(isCellV(true)).toBeTruthy();@@ -43,4 +87,25 @@ describe('Test cell data', () => {expect(isCellV(undefined)).toBeFalsy();expect(isCellV({})).toBeFalsy();});++ it('Function isNullCell', () => {+ expect(isNullCell(null)).toBeTruthy();+ expect(isNullCell(undefined)).toBeTruthy();+ expect(isNullCell({ v: null })).toBeTruthy();+ expect(isNullCell({ v: undefined })).toBeTruthy();+ expect(isNullCell({ v: '' })).toBeTruthy();+ expect(isNullCell({ p: null })).toBeTruthy();+ expect(isNullCell({ p: undefined })).toBeTruthy();+ expect(isNullCell({ f: null })).toBeTruthy();+ expect(isNullCell({ f: undefined })).toBeTruthy();+ expect(isNullCell({ f: '' })).toBeTruthy();+ expect(isNullCell({ si: null })).toBeTruthy();+ expect(isNullCell({ si: undefined })).toBeTruthy();+ expect(isNullCell({ si: '' })).toBeTruthy();++ expect(isNullCell({ v: 1 })).toBeFalsy();+ expect(isNullCell({ p: DOCUMENT_DATA })).toBeFalsy();+ expect(isNullCell({ f: '=SUM(A1)' })).toBeFalsy();+ expect(isNullCell({ si: 'id1' })).toBeFalsy();+ });});diff --git a/packages/core/src/types/interfaces/i-style-data.ts b/packages/core/src/types/interfaces/i-style-data.tsindex 31dd29602f..2a0d17d184 100644--- a/packages/core/src/types/interfaces/i-style-data.ts+++ b/packages/core/src/types/interfaces/i-style-data.ts@@ -175,6 +175,11 @@ export interface IStyleBase {* (Subscript 下标 /Superscript上标 Text)*/va?: Nullable<BaselineOffset>;++ /**+ * Numfmt pattern+ */+ n?: Nullable<{ pattern: string }>;}/**@@ -205,4 +210,5 @@ export interface IStyleData extends IStyleBase {* padding*/pd?: Nullable<IPaddingData>;+}diff --git a/packages/engine-formula/src/basics/common.ts b/packages/engine-formula/src/basics/common.tsindex cd369c2116..410c88890a 100644--- a/packages/engine-formula/src/basics/common.ts+++ b/packages/engine-formula/src/basics/common.ts@@ -25,6 +25,7 @@ import type {IUnitRange,Nullable,ObjectMatrix,+ Styles,} from '@univerjs/core';export const ERROR_VALUE_OBJECT_CLASS_TYPE = 'errorValueObject';@@ -65,6 +66,13 @@ export interface IUnitData {[unitId: string]: ISheetData;}+/**+ * Style data, numfmt needs to be queried from the style sheet+ */+export interface IUnitStylesData {+ [unitId: string]: Styles;+}+export interface IRuntimeUnitDataType {[unitId: string]: Nullable<{ [sheetId: string]: ObjectMatrix<Nullable<ICellData>> }>;}@@ -118,11 +126,6 @@ export interface IFormulaData {export interface IOtherFormulaData {[unitId: string]: Nullable<{ [subUnitId: string]: Nullable<{ [formulaId: string]: IFormulaDataItem }> }>;}--export interface INumfmtItemMap {- [unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType<Nullable<string>> }>;-}-/*** @f formulaString, the text string of the formula.* @si The formula ID can be utilized in scenarios such as copy-pasting and drag-filling to convert formulas into references, eliminating the need for recreating the formulaString.@@ -164,9 +167,9 @@ export interface IFormulaDatasetConfig {dirtyDefinedNameMap: IDirtyUnitSheetNameMap;dirtyUnitFeatureMap: IDirtyUnitFeatureMap;dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap;- numfmtItemMap: INumfmtItemMap;excludedCell?: IUnitExcludedCell;allUnitData?: IUnitData;+ unitStylesData?: IUnitStylesData;unitSheetNameMap?: IUnitSheetNameMap;}diff --git a/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts b/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.tsindex 1e441ee134..f6384cf6fd 100644--- a/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts+++ b/packages/engine-formula/src/commands/mutations/set-formula-calculation.mutation.ts@@ -22,7 +22,6 @@ import type {IDirtyUnitOtherFormulaMap,IDirtyUnitSheetDefinedNameMap,IDirtyUnitSheetNameMap,- INumfmtItemMap,IRuntimeOtherUnitDataType,IRuntimeUnitDataPrimitiveType,} from '../../basics/common';@@ -35,7 +34,6 @@ export interface ISetFormulaCalculationStartMutation {dirtyUnitFeatureMap: IDirtyUnitFeatureMap;dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap;options: Nullable<IExecutionOptions>;- numfmtItemMap: INumfmtItemMap;forceCalculation?: boolean;}/**diff --git a/packages/engine-formula/src/commands/mutations/set-numfmt-formula-data.mutation.ts b/packages/engine-formula/src/commands/mutations/set-numfmt-formula-data.mutation.tsdeleted file mode 100644index 7105cb4657..0000000000--- a/packages/engine-formula/src/commands/mutations/set-numfmt-formula-data.mutation.ts+++ /dev/null@@ -1,36 +0,0 @@-/**- * Copyright 2023-present DreamNum Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { IMutation } from '@univerjs/core';-import { CommandType } from '@univerjs/core';-import type { IAccessor } from '@wendellhu/redi';--import type { INumfmtItemMap } from '../../basics/common';-import { FormulaDataModel } from '../../models/formula-data.model';--export interface ISetNumfmtFormulaDataMutationParams {- numfmtItemMap: INumfmtItemMap;-}--export const SetNumfmtFormulaDataMutation: IMutation<ISetNumfmtFormulaDataMutationParams> = {- id: 'formula.mutation.set-numfmt-formula-data',- type: CommandType.MUTATION,- handler: (accessor: IAccessor, params: ISetNumfmtFormulaDataMutationParams) => {- const formulaDataModel = accessor.get(FormulaDataModel);- formulaDataModel.updateNumfmtItemMap(params.numfmtItemMap);- return true;- },-};diff --git a/packages/engine-formula/src/controller/calculate.controller.ts b/packages/engine-formula/src/controller/calculate.controller.tsindex 811f4347ce..232221935e 100644--- a/packages/engine-formula/src/controller/calculate.controller.ts+++ b/packages/engine-formula/src/controller/calculate.controller.ts@@ -15,10 +15,10 @@*/import type { ICommandInfo, IUnitRange } from '@univerjs/core';-import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';+import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';import { Inject } from '@wendellhu/redi';-import type { IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetDefinedNameMap, IDirtyUnitSheetNameMap, IFormulaData, INumfmtItemMap } from '../basics/common';+import type { IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetDefinedNameMap, IDirtyUnitSheetNameMap, IFormulaData } from '../basics/common';import type { ISetArrayFormulaDataMutationParams } from '../commands/mutations/set-array-formula-data.mutation';import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';import type { ISetFormulaCalculationStartMutation } from '../commands/mutations/set-formula-calculation.mutation';@@ -34,7 +34,6 @@ import { FormulaDataModel } from '../models/formula-data.model';import { CalculateFormulaService } from '../services/calculate-formula.service';import type { IAllRuntimeData } from '../services/runtime.service';import { FormulaExecutedStateType } from '../services/runtime.service';-import { SetNumfmtFormulaDataMutation } from '../commands/mutations/set-numfmt-formula-data.mutation';import { convertRuntimeToUnitData } from '../basics/runtime';@OnLifecycle(LifecycleStages.Ready, CalculateController)@@ -73,9 +72,9 @@ export class CalculateController extends Disposable {if (params.forceCalculation === true) {this._calculate(true);} else {- const { dirtyRanges, dirtyNameMap, dirtyDefinedNameMap, dirtyUnitFeatureMap, dirtyUnitOtherFormulaMap, numfmtItemMap } = params;+ const { dirtyRanges, dirtyNameMap, dirtyDefinedNameMap, dirtyUnitFeatureMap, dirtyUnitOtherFormulaMap } = params;- this._calculate(false, dirtyRanges, dirtyNameMap, dirtyDefinedNameMap, dirtyUnitFeatureMap, dirtyUnitOtherFormulaMap, numfmtItemMap);+ this._calculate(false, dirtyRanges, dirtyNameMap, dirtyDefinedNameMap, dirtyUnitFeatureMap, dirtyUnitOtherFormulaMap);}} else if (command.id === SetArrayFormulaDataMutation.id) {const params = command.params as ISetArrayFormulaDataMutationParams;@@ -99,8 +98,7 @@ export class CalculateController extends Disposable {dirtyNameMap: IDirtyUnitSheetNameMap = {},dirtyDefinedNameMap: IDirtyUnitSheetDefinedNameMap = {},dirtyUnitFeatureMap: IDirtyUnitFeatureMap = {},- dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap = {},- numfmtItemMap: INumfmtItemMap = {}+ dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap = {}) {if (dirtyRanges.length === 0 &&@@ -126,7 +124,6 @@ export class CalculateController extends Disposable {dirtyDefinedNameMap,dirtyUnitFeatureMap,dirtyUnitOtherFormulaMap,- numfmtItemMap,});}@@ -197,7 +194,7 @@ export class CalculateController extends Disposable {}private async _applyFormula(data: IAllRuntimeData) {- const { unitData, unitOtherData, arrayFormulaRange, arrayFormulaCellData, clearArrayFormulaCellData, numfmtItemMap } = data;+ const { unitData, unitOtherData, arrayFormulaRange, arrayFormulaCellData, clearArrayFormulaCellData } = data;if (!unitData) {console.error('No sheetData from Formula Engine!');@@ -226,19 +223,6 @@ export class CalculateController extends Disposable {);}- // Synchronous to the main thread- if (!Tools.isEmptyObject(numfmtItemMap)) {- this._commandService.executeCommand(- SetNumfmtFormulaDataMutation.id,- {- numfmtItemMap,- },- {- onlyLocal: true,- }- );- }-this._commandService.executeCommand(SetFormulaCalculationResultMutation.id,{diff --git a/packages/engine-formula/src/controller/formula.controller.ts b/packages/engine-formula/src/controller/formula.controller.tsindex 3291cbc3c9..94acf29f34 100644--- a/packages/engine-formula/src/controller/formula.controller.ts+++ b/packages/engine-formula/src/controller/formula.controller.ts@@ -58,7 +58,6 @@ import { functionText } from '../functions/text/function-map';import { functionUniver } from '../functions/univer/function-map';import { functionWeb } from '../functions/web/function-map';import { IFunctionService } from '../services/function.service';-import { SetNumfmtFormulaDataMutation } from '../commands/mutations/set-numfmt-formula-data.mutation';@OnLifecycle(LifecycleStages.Ready, FormulaController)export class FormulaController extends Disposable {@@ -86,7 +85,6 @@ export class FormulaController extends Disposable {SetFormulaCalculationStopMutation,SetFormulaCalculationNotificationMutation,SetFormulaCalculationResultMutation,- SetNumfmtFormulaDataMutation,SetDefinedNameMutation,RemoveDefinedNameMutation,diff --git a/packages/engine-formula/src/engine/analysis/__tests__/parser.spec.ts b/packages/engine-formula/src/engine/analysis/__tests__/parser.spec.tsindex eb15315d2f..63ee98552a 100644--- a/packages/engine-formula/src/engine/analysis/__tests__/parser.spec.ts+++ b/packages/engine-formula/src/engine/analysis/__tests__/parser.spec.ts@@ -61,7 +61,6 @@ describe('Test indirect', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/engine/ast-node/reference-node.ts b/packages/engine-formula/src/engine/ast-node/reference-node.tsindex 130b7691a6..c59241ba61 100644--- a/packages/engine-formula/src/engine/ast-node/reference-node.ts+++ b/packages/engine-formula/src/engine/ast-node/reference-node.ts@@ -72,7 +72,7 @@ export class ReferenceNode extends BaseAstNode {this._referenceObject.setRuntimeData(runtimeService.getUnitData());- this._referenceObject.setNumfmtItemData(currentConfigService.getNumfmtItemMap());+ this._referenceObject.setUnitStylesData(currentConfigService.getUnitStylesData());this._referenceObject.setRuntimeArrayFormulaCellData(runtimeService.getRuntimeArrayFormulaCellData());diff --git a/packages/engine-formula/src/engine/reference-object/base-reference-object.ts b/packages/engine-formula/src/engine/reference-object/base-reference-object.tsindex e887f39afd..8e527a13d6 100644--- a/packages/engine-formula/src/engine/reference-object/base-reference-object.ts+++ b/packages/engine-formula/src/engine/reference-object/base-reference-object.ts@@ -18,7 +18,7 @@ import type { ICellData, IRange, Nullable } from '@univerjs/core';import { CellValueType, isNullCell, moveRangeByOffset } from '@univerjs/core';import { FormulaAstLRU } from '../../basics/cache-lru';-import type { INumfmtItemMap, IRuntimeUnitDataType, IUnitData, IUnitSheetNameMap } from '../../basics/common';+import type { IRuntimeUnitDataType, IUnitData, IUnitSheetNameMap, IUnitStylesData } from '../../basics/common';import { ERROR_TYPE_SET, ErrorType } from '../../basics/error-type';import { ObjectClassType } from '../../basics/object-class-type';import { ArrayValueObject, ValueObjectFactory } from '../value-object/array-value-object';@@ -55,6 +55,8 @@ export class BaseReferenceObject extends ObjectClassType {private _unitData: IUnitData = {};+ private _unitStylesData: IUnitStylesData = {};+private _defaultUnitId: string = '';private _forcedUnitId: string = '';@@ -67,8 +69,6 @@ export class BaseReferenceObject extends ObjectClassType {private _runtimeFeatureCellData: { [featureId: string]: IRuntimeUnitDataType } = {};- private _numfmtItemData: INumfmtItemMap = {};-private _refOffsetX = 0;private _refOffsetY = 0;@@ -80,6 +80,8 @@ export class BaseReferenceObject extends ObjectClassType {override dispose(): void {this._unitData = {};+ this._unitStylesData = {};+this._runtimeData = {};}@@ -163,16 +165,18 @@ export class BaseReferenceObject extends ObjectClassType {const cell = this.getCellData(r, c);let result: Nullable<boolean> = false;- if (cell == null || isNullCell(cell)) {+ if (isNullCell(cell)) {result = callback(null, r, c);continue;}const resultObjectValue = this.getCellValueObject(cell);- const isNumber = resultObjectValue.isNumber();- const pattern = this._numfmtItemData[unitId]?.[sheetId]?.[r]?.[c];- pattern && isNumber && resultObjectValue.setPattern(pattern);+ // Set numfmt pattern for first cell, it does not have to be a number, the string can also be set a number format+ if (r === startRow && c === startColumn) {+ const pattern = this.getCellPattern(unitId, sheetId, r, c);+ pattern && resultObjectValue.setPattern(pattern);+ }result = callback(resultObjectValue, r, c);@@ -192,13 +196,12 @@ export class BaseReferenceObject extends ObjectClassType {}const cellValueObject = this.getCellValueObject(cell);- const isNumber = cellValueObject.isNumber();- // Set numfmt pattern+ // Set numfmt pattern, it does not have to be a number, the string can also be set a number formatconst unitId = this._forcedUnitId || this._defaultUnitId;const sheetId = this._forcedSheetId || this._defaultSheetId;- const numfmtItem = this._numfmtItemData[unitId]?.[sheetId]?.[startRow]?.[startColumn];- numfmtItem && isNumber && cellValueObject.setPattern(numfmtItem);+ const pattern = this.getCellPattern(unitId, sheetId, startRow, startColumn);+ pattern && cellValueObject.setPattern(pattern);return cellValueObject;}@@ -281,6 +284,14 @@ export class BaseReferenceObject extends ObjectClassType {this._unitData = unitData;}+ getUnitStylesData() {+ return this._unitStylesData;+ }++ setUnitStylesData(unitStylesData: IUnitStylesData) {+ this._unitStylesData = unitStylesData;+ }+getRuntimeData() {return this._runtimeData;}@@ -313,14 +324,6 @@ export class BaseReferenceObject extends ObjectClassType {this._runtimeFeatureCellData = unitData;}- getNumfmtItemData() {- return this._numfmtItemData;- }-- setNumfmtItemData(numfmtItemData: INumfmtItemMap) {- this._numfmtItemData = numfmtItemData;- }-getActiveSheetRowCount() {return this.getCurrentActiveSheetData()?.rowCount || 0;}@@ -411,6 +414,10 @@ export class BaseReferenceObject extends ObjectClassType {return this._unitData[this.getUnitId()]?.[this.getSheetId()];}+ getCurrentStylesData() {+ return this._unitStylesData[this.getUnitId()];+ }+getCurrentRuntimeSheetData() {return this._runtimeData?.[this.getUnitId()]?.[this.getSheetId()];}@@ -479,6 +486,32 @@ export class BaseReferenceObject extends ObjectClassType {return this.getCellValueObject(cell);}+ /**+ * Get the pattern of the cell+ * @param unitId+ * @param sheetId+ * @param row+ * @param column+ * @returns+ */+ getCellPattern(unitId: string, sheetId: string, row: number, column: number) {+ const currentStyles = this._unitStylesData[unitId];++ if (!currentStyles) {+ return '';+ }++ const currentCell = this._unitData[unitId]?.[sheetId]?.cellData?.getValue(row, column);++ if (!currentCell) {+ return '';+ }++ const style = currentStyles.getStyleByCell(currentCell);++ return style?.n?.pattern || '';+ }+toArrayValueObject(useCache: boolean = true): ArrayValueObject {const { startRow, endRow, startColumn, endColumn } = this.getRangePosition();diff --git a/packages/engine-formula/src/engine/reference-object/cell-reference-object.ts b/packages/engine-formula/src/engine/reference-object/cell-reference-object.tsindex 3d521d2467..7e7b5d9d53 100644--- a/packages/engine-formula/src/engine/reference-object/cell-reference-object.ts+++ b/packages/engine-formula/src/engine/reference-object/cell-reference-object.ts@@ -104,7 +104,7 @@ export class CellReferenceObject extends BaseReferenceObject {rangeReferenceObject.setRuntimeData(this.getRuntimeData());- rangeReferenceObject.setNumfmtItemData(this.getNumfmtItemData());+ rangeReferenceObject.setUnitStylesData(this.getUnitStylesData());rangeReferenceObject.setArrayFormulaCellData(this.getArrayFormulaCellData());diff --git a/packages/engine-formula/src/engine/utils/__tests__/value-object.spec.ts b/packages/engine-formula/src/engine/utils/__tests__/value-object.spec.tsindex 2f44cd38f6..9f1a04b18e 100644--- a/packages/engine-formula/src/engine/utils/__tests__/value-object.spec.ts+++ b/packages/engine-formula/src/engine/utils/__tests__/value-object.spec.ts@@ -16,8 +16,8 @@import { describe, expect, it } from 'vitest';-import { cellToRange } from '@univerjs/core';-import { convertTonNumber, isSingleValueObject } from '../value-object';+import { cellToRange, CellValueType } from '@univerjs/core';+import { convertTonNumber, isSingleValueObject, objectValueToCellValue } from '../value-object';import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../value-object/primitive-object';import { ErrorValueObject } from '../../value-object/base-value-object';import { ErrorType } from '../../../basics/error-type';@@ -55,4 +55,14 @@ describe('Test object cover', () => {expect(isSingleValueObject(new RangeReferenceObject(cellToRange(0, 1)))).toBe(true);expect(isSingleValueObject(new RangeReferenceObject({ startRow: 0, endRow: 1, startColumn: 0, endColumn: 1 }))).toBe(false);});++ it('Function objectValueToCellValue', () => {+ expect(objectValueToCellValue(NumberValueObject.create(1))).toStrictEqual({ v: 1, t: CellValueType.NUMBER });+ expect(objectValueToCellValue(StringValueObject.create('Univer'))).toStrictEqual({ v: 'Univer', t: CellValueType.STRING });+ expect(objectValueToCellValue(BooleanValueObject.create(true))).toStrictEqual({ v: 1, t: CellValueType.BOOLEAN });+ expect(objectValueToCellValue(BooleanValueObject.create(false))).toStrictEqual({ v: 0, t: CellValueType.BOOLEAN });+ expect(objectValueToCellValue(NullValueObject.create())).toStrictEqual({ v: null });+ expect(objectValueToCellValue(null)).toStrictEqual({ v: null });+ expect(objectValueToCellValue(ErrorValueObject.create(ErrorType.VALUE))).toStrictEqual({ v: ErrorType.VALUE, t: CellValueType.STRING });+ });});diff --git a/packages/engine-formula/src/engine/utils/value-object.ts b/packages/engine-formula/src/engine/utils/value-object.tsindex 168edabfb6..6fcd4604fc 100644--- a/packages/engine-formula/src/engine/utils/value-object.ts+++ b/packages/engine-formula/src/engine/utils/value-object.ts@@ -14,9 +14,11 @@* limitations under the License.*/+import type { ICellData, Nullable } from '@univerjs/core';+import { CellValueType, isRealNum } from '@univerjs/core';import type { BaseReferenceObject, FunctionVariantType } from '../reference-object/base-reference-object';import type { ArrayValueObject } from '../value-object/array-value-object';-import type { BaseValueObject } from '../value-object/base-value-object';+import type { BaseValueObject, ErrorValueObject } from '../value-object/base-value-object';import { NumberValueObject } from '../value-object/primitive-object';export function convertTonNumber(valueObject: BaseValueObject) {@@ -53,3 +55,76 @@ export function isSingleValueObject(valueObject: FunctionVariantType) {return false;}++/**+ * Covert BaseValueObject to cell value+ * @param objectValue+ * @returns+ */+export function objectValueToCellValue(objectValue: Nullable<BaseValueObject>): ICellData | undefined {+ const pattern = objectValue?.getPattern();+ let cellWithStyle: ICellData = {};++ if (pattern) {+ cellWithStyle = {+ s: {+ n: {+ pattern,+ },+ },+ };+ }++ if (objectValue == null) {+ return {+ v: null,+ ...cellWithStyle,+ };+ }+ if (objectValue.isError()) {+ return {+ v: (objectValue as ErrorValueObject).getErrorType() as string,+ t: CellValueType.STRING,+ ...cellWithStyle,+ };+ }+ if (objectValue.isValueObject()) {+ const vo = objectValue as BaseValueObject;+ const v = vo.getValue();+ if (vo.isNumber()) {+ return {+ v,+ t: CellValueType.NUMBER,+ ...cellWithStyle,+ };+ }+ if (vo.isBoolean()) {+ return {+ v: v ? 1 : 0,+ t: CellValueType.BOOLEAN,+ ...cellWithStyle,+ };+ }+ // String "00"+ if (vo.isString() && isRealNum(v)) {+ return {+ v,+ t: CellValueType.FORCE_STRING,+ ...cellWithStyle,+ };+ }++ if (vo.isNull()) {+ return {+ v: null,+ ...cellWithStyle,+ };+ }++ return {+ v,+ t: CellValueType.STRING,+ ...cellWithStyle,+ };+ }+}diff --git a/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts b/packages/engine-formula/src/functions/__tests__/nested-functions.spec.tsindex 3003f44669..9b1e09eaee 100644--- a/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts+++ b/packages/engine-formula/src/functions/__tests__/nested-functions.spec.ts@@ -273,7 +273,6 @@ describe('Test nested functions', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.ts b/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.tsindex 685e705186..ee3e0fd07c 100644--- a/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/information/isref/__tests__/index.spec.ts@@ -166,7 +166,6 @@ describe('Test isref function', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.tsindex dae3685391..ee56eadac0 100644--- a/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/lookup/column/__tests__/index.spec.ts@@ -57,7 +57,6 @@ describe('Test column', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.tsindex efb45c0c35..c63c81606c 100644--- a/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/lookup/columns/__tests__/index.spec.ts@@ -56,7 +56,6 @@ describe('Test columns', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.ts b/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.tsindex 68a9403886..9ef275837d 100644--- a/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.ts+++ b/packages/engine-formula/src/functions/lookup/index/__test__/index.spec.ts@@ -165,7 +165,6 @@ describe('Test index', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/functions/lookup/indirect/__test__/index.spec.ts b/packages/engine-formula/src/functions/lookup/indirect/__test__/index.spec.tsindex 2fce8b3aee..838c4a0741 100644--- a/packages/engine-formula/src/functions/lookup/indirect/__test__/index.spec.ts+++ b/packages/engine-formula/src/functions/lookup/indirect/__test__/index.spec.ts@@ -60,7 +60,6 @@ describe('Test indirect', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/functions/lookup/offset/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/offset/__tests__/index.spec.tsindex d6dffce880..92c9efce2f 100644--- a/packages/engine-formula/src/functions/lookup/offset/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/lookup/offset/__tests__/index.spec.ts@@ -160,7 +160,6 @@ describe('Test offset', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.tsindex ab91e99038..d905eecb97 100644--- a/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/lookup/row/__tests__/index.spec.ts@@ -57,7 +57,6 @@ describe('Test row', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.ts b/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.tsindex afd8487d7a..20cdd22e84 100644--- a/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/lookup/rows/__tests__/index.spec.ts@@ -56,7 +56,6 @@ describe('Test rows', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.tsindex 625a262232..d254f65987 100644--- a/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/math/subtotal/__tests__/index.spec.ts@@ -157,7 +157,6 @@ describe('Test subtotal', () => {formulaData: {},arrayFormulaCellData: {},forceCalculate: false,- numfmtItemMap: {},dirtyRanges: [],dirtyNameMap: {},dirtyDefinedNameMap: {},diff --git a/packages/engine-formula/src/index.ts b/packages/engine-formula/src/index.tsindex 8987d52b0e..4af72e4974 100644--- a/packages/engine-formula/src/index.ts+++ b/packages/engine-formula/src/index.ts@@ -27,7 +27,6 @@ export type {ISheetData,IUnitData,IUnitSheetNameMap,- INumfmtItemMap,IDirtyUnitOtherFormulaMap,IDirtyUnitSheetDefinedNameMap,} from './basics/common';@@ -140,8 +139,6 @@ export { IFunctionService } from './services/function.service';export { IOtherFormulaManagerService, OtherFormulaManagerService } from './services/other-formula-manager.service';export { FormulaExecuteStageType, type IExecutionInProgressParams } from './services/runtime.service';export { FormulaExecutedStateType, type IAllRuntimeData } from './services/runtime.service';-export { SetNumfmtFormulaDataMutation } from './commands/mutations/set-numfmt-formula-data.mutation';-export type { ISetNumfmtFormulaDataMutationParams } from './commands/mutations/set-numfmt-formula-data.mutation';export { isReferenceString } from './basics/regex';export { matchRefDrawToken } from './basics/match-token';export { IDefinedNamesService, DefinedNamesService, type IDefinedNamesServiceParam, type IDefinedNameMapItem } from './services/defined-names.service';diff --git a/packages/engine-formula/src/models/__tests__/formula-data.model.spec.ts b/packages/engine-formula/src/models/__tests__/formula-data.model.spec.tsindex ba1dbcad2f..e9cb107a51 100644--- a/packages/engine-formula/src/models/__tests__/formula-data.model.spec.ts+++ b/packages/engine-formula/src/models/__tests__/formula-data.model.spec.ts@@ -350,91 +350,6 @@ describe('Test formula data model', () => {expect(formulaData).toStrictEqual(result);});});-- describe('updateNumfmtData', () => {- it('update numfmt data', () => {- const unitId = 'test';- const sheetId = 'sheet1';-- formulaDataModel.setNumfmtItemMap({- [unitId]: {- [sheetId]: {- 0: {- 3: '0.00',- },- },- },- });-- const cellValue = {- 0: {- 3: {- v: null,- p: null,- f: null,- si: null,- },- },- };-- const result = {- [unitId]: {- [sheetId]: {- 0: {- 3: null,- },- },- },- };-- formulaDataModel.updateNumfmtData(unitId, sheetId, cellValue);-- const numfmtData = formulaDataModel.getNumfmtItemMap();- expect(numfmtData).toStrictEqual(result);- });- });-- describe('updateNumfmtMap', () => {- it('update numfmt map data', () => {- const unitId = 'test';- const sheetId = 'sheet1';-- formulaDataModel.setNumfmtItemMap({- [unitId]: {- [sheetId]: {- 0: {- 3: '0.00',- },- },- },- });-- const numfmtItemMap = {- [unitId]: {- [sheetId]: {- 0: {- 3: null,- },- },- },- };-- const result = {- [unitId]: {- [sheetId]: {- 0: {- 3: null,- },- },- },- };-- formulaDataModel.updateNumfmtItemMap(numfmtItemMap);-- const numfmtData = formulaDataModel.getNumfmtItemMap();- expect(numfmtData).toStrictEqual(result);- });- });});describe('function initSheetFormulaData', () => {diff --git a/packages/engine-formula/src/models/formula-data.model.ts b/packages/engine-formula/src/models/formula-data.model.tsindex 67ab5d5a16..65679df7ec 100644--- a/packages/engine-formula/src/models/formula-data.model.ts+++ b/packages/engine-formula/src/models/formula-data.model.ts@@ -23,7 +23,6 @@ import type {IArrayFormulaUnitCellType,IFormulaData,IFormulaDataItem,- INumfmtItemMap,IRuntimeUnitDataType,ISheetData,IUnitData,@@ -46,9 +45,6 @@ export class FormulaDataModel extends Disposable {private _arrayFormulaCellData: IArrayFormulaUnitCellType = {};- // TODO@Dushusir: Determine the node.js environment and synchronize to the resource plugin when SSC is used- private _numfmtItemMap: INumfmtItemMap = {};-constructor(@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,@Inject(LexerTreeBuilder) private readonly _lexerTreeBuilder: LexerTreeBuilder@@ -172,49 +168,6 @@ export class FormulaDataModel extends Disposable {this._arrayFormulaCellData = value;}- getNumfmtItemMap() {- return this._numfmtItemMap;- }-- getNumfmtValue(unitId: string, sheetId: string, row: number, column: number) {- return this._numfmtItemMap[unitId]?.[sheetId]?.[row]?.[column];- }-- setNumfmtItemMap(value: INumfmtItemMap) {- this._numfmtItemMap = value;- }-- updateNumfmtItemMap(value: INumfmtItemMap) {- Object.keys(value).forEach((unitId) => {- const sheetData = value[unitId];-- if (sheetData == null) {- return true;- }-- if (this._numfmtItemMap[unitId] == null) {- this._numfmtItemMap[unitId] = {};- }-- Object.keys(sheetData).forEach((sheetId) => {- const numfmtItemMap = sheetData[sheetId];- const numfmtItemMatrix = new ObjectMatrix(numfmtItemMap);-- if (this._numfmtItemMap[unitId]![sheetId] == null) {- this._numfmtItemMap[unitId]![sheetId] = {};- }-- numfmtItemMatrix.forValue((r, c, numfmtItem) => {- if (this._numfmtItemMap[unitId]![sheetId][r] == null) {- this._numfmtItemMap[unitId]![sheetId][r] = {};- }-- this._numfmtItemMap[unitId]![sheetId][r][c] = numfmtItem;- });- });- });- }-mergeArrayFormulaRange(formulaData: IArrayFormulaRangeType) {Object.keys(formulaData).forEach((unitId) => {const sheetData = formulaData[unitId];@@ -484,46 +437,6 @@ export class FormulaDataModel extends Disposable {});}- updateNumfmtData(- unitId: string,- sheetId: string,- cellValue: IObjectMatrixPrimitiveType<Nullable<ICellData>>- ) {- // remove the array formula range when cell value is null-- const arrayFormulaRange = this._arrayFormulaRange[unitId]?.[sheetId];- const arrayFormulaRangeMatrix = new ObjectMatrix(arrayFormulaRange);-- const numfmtData = this._numfmtItemMap[unitId]?.[sheetId];-- if (!numfmtData) return;-- const numfmtDataMatrix = new ObjectMatrix(numfmtData);-- const cellMatrix = new ObjectMatrix(cellValue);- cellMatrix.forValue((r, c, cell) => {- const formulaString = cell?.f || '';- const formulaId = cell?.si || '';-- const checkFormulaString = isFormulaString(formulaString);- const checkFormulaId = isFormulaId(formulaId);-- if (!checkFormulaString && !checkFormulaId) {- numfmtDataMatrix.setValue(r, c, null);-- const arrayFormulaRangeValue = arrayFormulaRangeMatrix.getValue(r, c);- if (arrayFormulaRangeValue) {- const { startRow, startColumn, endRow, endColumn } = arrayFormulaRangeValue;- for (let row = startRow; row <= endRow; row++) {- for (let column = startColumn; column <= endColumn; column++) {- numfmtDataMatrix.setValue(row, column, null);- }- }- }- }- });- }-getFormulaItemBySId(sId: string, sheetId: string, unitId: string): Nullable<IFormulaDataItem> {const formulaData = this._formulaData;if (formulaData[unitId] == null) {diff --git a/packages/engine-formula/src/services/current-data.service.ts b/packages/engine-formula/src/services/current-data.service.tsindex 951710df32..95bcc41c47 100644--- a/packages/engine-formula/src/services/current-data.service.ts+++ b/packages/engine-formula/src/services/current-data.service.ts@@ -25,13 +25,13 @@ import type {IDirtyUnitSheetNameMap,IFormulaData,IFormulaDatasetConfig,- INumfmtItemMap,IRuntimeUnitDataType,ISheetData,IUnitData,IUnitExcludedCell,IUnitSheetIdToNameMap,IUnitSheetNameMap,+ IUnitStylesData,} from '../basics/common';import { convertUnitDataToRuntime } from '../basics/runtime';@@ -42,6 +42,11 @@ export interface IFormulaCurrentConfigService {getUnitData(): IUnitData;+ /**+ * Get the unit styles data.+ */+ getUnitStylesData(): IUnitStylesData;+getFormulaData(): IFormulaData;getSheetNameMap(): IUnitSheetNameMap;@@ -77,12 +82,13 @@ export interface IFormulaCurrentConfigService {setExecuteUnitId(unitId: string): void;setExecuteSubUnitId(subUnitId: string): void;-}export class FormulaCurrentConfigService extends Disposable implements IFormulaCurrentConfigService {private _unitData: IUnitData = {};+ private _unitStylesData: IUnitStylesData = {};+private _arrayFormulaCellData: IRuntimeUnitDataType = {};private _formulaData: IFormulaData = {};@@ -97,8 +103,6 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaCprivate _dirtyDefinedNameMap: IDirtyUnitSheetDefinedNameMap = {};- private _numfmtItemMap: INumfmtItemMap = {};-private _dirtyUnitFeatureMap: IDirtyUnitFeatureMap = {};private _dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap = {};@@ -116,13 +120,13 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaCoverride dispose(): void {this._unitData = {};+ this._unitStylesData = {};this._formulaData = {};this._arrayFormulaCellData = {};this._sheetNameMap = {};this._dirtyRanges = [];this._dirtyNameMap = {};this._dirtyDefinedNameMap = {};- this._numfmtItemMap = {};this._dirtyUnitFeatureMap = {};this._excludedCell = {};this._sheetIdToNameMap = {};@@ -153,6 +157,10 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaCreturn this._unitData;}+ getUnitStylesData(): IUnitStylesData {+ return this._unitStylesData;+ }+getFormulaData() {return this._formulaData;}@@ -181,10 +189,6 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaCreturn this._dirtyDefinedNameMap;}- getNumfmtItemMap() {- return this._numfmtItemMap;- }-getDirtyUnitFeatureMap() {return this._dirtyUnitFeatureMap;}@@ -202,14 +206,17 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaC}load(config: IFormulaDatasetConfig) {- if (config.allUnitData && config.unitSheetNameMap) {+ if (config.allUnitData && config.unitSheetNameMap && config.unitStylesData) {this._unitData = config.allUnitData;+ this._unitStylesData = config.unitStylesData;this._sheetNameMap = config.unitSheetNameMap;} else {- const { allUnitData, unitSheetNameMap } = this._loadSheetData();+ const { allUnitData, unitSheetNameMap, unitStylesData } = this._loadSheetData();this._unitData = allUnitData;+ this._unitStylesData = unitStylesData;+this._sheetNameMap = unitSheetNameMap;}@@ -225,8 +232,6 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaCthis._dirtyDefinedNameMap = config.dirtyDefinedNameMap;- this._numfmtItemMap = config.numfmtItemMap;-this._dirtyUnitFeatureMap = config.dirtyUnitFeatureMap;this._dirtyUnitOtherFormulaMap = config.dirtyUnitOtherFormulaMap;@@ -371,6 +376,8 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaCconst allUnitData: IUnitData = {};+ const unitStylesData: IUnitStylesData = {};+const unitSheetNameMap: IUnitSheetNameMap = {};for (const workbook of unitAllSheet) {@@ -398,11 +405,14 @@ export class FormulaCurrentConfigService extends Disposable implements IFormulaCallUnitData[unitId] = sheetData;+ unitStylesData[unitId] = workbook.getStyles();+unitSheetNameMap[unitId] = sheetNameMap;}return {allUnitData,+ unitStylesData,unitSheetNameMap,};}diff --git a/packages/engine-formula/src/services/runtime.service.ts b/packages/engine-formula/src/services/runtime.service.tsindex fd9d148cac..e10c90d1f6 100644--- a/packages/engine-formula/src/services/runtime.service.ts+++ b/packages/engine-formula/src/services/runtime.service.ts@@ -15,13 +15,12 @@*/import type { ICellData, IRange, Nullable } from '@univerjs/core';-import { CellValueType, Disposable, isNullCell, isRealNum, ObjectMatrix } from '@univerjs/core';+import { Disposable, isNullCell, ObjectMatrix } from '@univerjs/core';import { createIdentifier } from '@wendellhu/redi';import type {IArrayFormulaRangeType,IFeatureDirtyRangeType,- INumfmtItemMap,IRuntimeOtherUnitDataType,IRuntimeUnitDataType,} from '../basics/common';@@ -31,6 +30,7 @@ import type { BaseAstNode } from '../engine/ast-node/base-ast-node';import type { BaseReferenceObject, FunctionVariantType } from '../engine/reference-object/base-reference-object';import type { ArrayValueObject } from '../engine/value-object/array-value-object';import { type BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';+import { objectValueToCellValue } from '../engine/utils/value-object';import { IFormulaCurrentConfigService } from './current-data.service';/**@@ -67,7 +67,6 @@ export interface IAllRuntimeData {functionsExecutedState: FormulaExecutedStateType;arrayFormulaCellData: IRuntimeUnitDataType;clearArrayFormulaCellData: IRuntimeUnitDataType;- numfmtItemMap: INumfmtItemMap;runtimeFeatureRange: { [featureId: string]: IFeatureDirtyRangeType };runtimeFeatureCellData: { [featureId: string]: IRuntimeUnitDataType };@@ -196,8 +195,6 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeprivate _runtimeClearArrayFormulaCellData: IRuntimeUnitDataType = {};- private _numfmtItemMap: INumfmtItemMap = {};-private _runtimeFeatureRange: { [featureId: string]: IFeatureDirtyRangeType } = {};private _runtimeFeatureCellData: { [featureId: string]: IRuntimeUnitDataType } = {};@@ -334,7 +331,6 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimethis._runtimeData = {};this._runtimeOtherData = {};this._unitArrayFormulaRange = {};- this._numfmtItemMap = {};this._runtimeArrayFormulaCellData = {};this._runtimeClearArrayFormulaCellData = {};@@ -396,7 +392,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeconst objectValueRefOrArray = functionVariant as BaseReferenceObject | ArrayValueObject;const { startRow, startColumn } = objectValueRefOrArray.getRangePosition();objectValueRefOrArray.iterator((valueObject, rowIndex, columnIndex) => {- const value = this._objectValueToCellValue(valueObject);+ const value = objectValueToCellValue(valueObject);const row = rowIndex - startRow;const column = columnIndex - startColumn;@@ -407,7 +403,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimecellDatas[row][column] = value;});} else {- cellDatas = [[this._objectValueToCellValue(functionVariant as BaseValueObject)!]];+ cellDatas = [[objectValueToCellValue(functionVariant as BaseValueObject)!]];}subComponentData![formulaId] = cellDatas;@@ -435,16 +431,6 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimethis._unitArrayFormulaRange[unitId] = {};}- if (this._numfmtItemMap[unitId] == null) {- this._numfmtItemMap[unitId] = {};- }-- if (this._numfmtItemMap[unitId]![sheetId] == null) {- this._numfmtItemMap[unitId]![sheetId] = {};- }-- const numfmtItem = this._numfmtItemMap[unitId]![sheetId];-const arrayFormulaRange = this._unitArrayFormulaRange[unitId]!;let arrayData = new ObjectMatrix<IRange>();@@ -493,16 +479,11 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime*/if (startRow === endRow && startColumn === endColumn) {const firstCell = objectValueRefOrArray.getFirstCell();- const valueObject = this._objectValueToCellValue(firstCell);+ // TODO @Dushusir set pattern style+ const valueObject = objectValueToCellValue(firstCell);sheetData.setValue(row, column, valueObject);clearArrayUnitData.setValue(row, column, valueObject);- if (numfmtItem[row] == null) {- numfmtItem[row] = {};- }-- numfmtItem[row]![column] = firstCell.getPattern();-return;}@@ -521,13 +502,13 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimethis._checkIfArrayFormulaRangeHasData(unitId, sheetId, row, column, arrayRange) ||this._checkIfArrayFormulaExceeded(rowCount, columnCount, arrayRange)) {- const errorObject = this._objectValueToCellValue(ErrorValueObject.create(ErrorType.SPILL));+ const errorObject = objectValueToCellValue(ErrorValueObject.create(ErrorType.SPILL));sheetData.setValue(row, column, errorObject);clearArrayUnitData.setValue(row, column, errorObject);} else {const spillError = ErrorValueObject.create(ErrorType.SPILL);objectValueRefOrArray.iterator((valueObject, rowIndex, columnIndex) => {- const value = this._objectValueToCellValue(valueObject);+ const value = objectValueToCellValue(valueObject);if (rowIndex === startRow && columnIndex === startColumn) {/*** If the referenced range contains an error in the spill of the array formula,@@ -535,7 +516,7 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime*/if (valueObject != null && valueObject.isError() && valueObject.isEqualType(spillError)) {clearArrayUnitData.setValue(row, column, {});- sheetData.setValue(row, column, { ...this._objectValueToCellValue(spillError) });+ sheetData.setValue(row, column, { ...objectValueToCellValue(spillError) });return false;}sheetData.setValue(row, column, { ...value });@@ -545,27 +526,12 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimeconst currentColumn = columnIndex - startColumn + column;arrayUnitData.setValue(currentRow, currentColumn, value);-- const pattern = valueObject?.getPattern();- if (pattern) {- if (numfmtItem[currentRow] == null) {- numfmtItem[currentRow] = {};- }-- numfmtItem[currentRow]![currentColumn] = pattern;- }});}} else {- const valueObject = this._objectValueToCellValue(functionVariant as BaseValueObject);+ const valueObject = objectValueToCellValue(functionVariant as BaseValueObject);sheetData.setValue(row, column, valueObject);- if (numfmtItem[row] == null) {- numfmtItem[row] = {};- }-- numfmtItem[row]![column] = functionVariant.getPattern();-clearArrayUnitData.setValue(row, column, valueObject);}}@@ -578,10 +544,6 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimereturn this._unitArrayFormulaRange;}- getNumfmtItemMap() {- return this._numfmtItemMap;- }-getRuntimeOtherData() {return this._runtimeOtherData;}@@ -618,7 +580,6 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntimefunctionsExecutedState: this._functionsExecutedState,arrayFormulaCellData: this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData: this.getRuntimeClearArrayFormulaCellData(),- numfmtItemMap: this.getNumfmtItemMap(),runtimeFeatureRange: this.getRuntimeFeatureRange(),runtimeFeatureCellData: this.getRuntimeFeatureCellData(),@@ -639,47 +600,6 @@ export class FormulaRuntimeService extends Disposable implements IFormulaRuntime};}- private _objectValueToCellValue(objectValue: Nullable<BaseValueObject>) {- if (objectValue == null) {- return {- v: null,- };- }- if (objectValue.isError()) {- return {- v: (objectValue as ErrorValueObject).getErrorType() as string,- t: CellValueType.STRING,- };- }- if (objectValue.isValueObject()) {- const vo = objectValue as BaseValueObject;- const v = vo.getValue();- if (vo.isNumber()) {- return {- v,- t: CellValueType.NUMBER,- };- }- if (vo.isBoolean()) {- return {- v,- t: CellValueType.BOOLEAN,- };- }- // String "00"- if (vo.isString() && isRealNum(v)) {- return {- v,- t: CellValueType.FORCE_STRING,- };- }- return {- v,- t: CellValueType.STRING,- };- }- }-private _checkIfArrayFormulaRangeHasData(formulaUnitId: string,formulaSheetId: string,diff --git a/packages/sheets-formula/src/controllers/__tests__/update-formula.controller.spec.ts b/packages/sheets-formula/src/controllers/__tests__/update-formula.controller.spec.tsindex 8355330a06..2c6d2b61c9 100644--- a/packages/sheets-formula/src/controllers/__tests__/update-formula.controller.spec.ts+++ b/packages/sheets-formula/src/controllers/__tests__/update-formula.controller.spec.ts@@ -21,7 +21,7 @@ import { DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, InsertColCommand,import type { Injector } from '@wendellhu/redi';import { afterEach, beforeEach, describe, expect, it } from 'vitest';-import { SetArrayFormulaDataMutation, SetFormulaDataMutation, SetNumfmtFormulaDataMutation } from '@univerjs/engine-formula';+import { SetArrayFormulaDataMutation, SetFormulaDataMutation } from '@univerjs/engine-formula';import { UpdateFormulaController } from '../update-formula.controller';import { createCommandTestBed } from './create-command-test-bed';@@ -145,7 +145,6 @@ describe('Test insert function operation', () => {commandService.registerCommand(SetRangeValuesMutation);commandService.registerCommand(SetFormulaDataMutation);commandService.registerCommand(SetArrayFormulaDataMutation);- commandService.registerCommand(SetNumfmtFormulaDataMutation);getValues = (startRow: number,diff --git a/packages/sheets-formula/src/controllers/array-formula-display.controller.ts b/packages/sheets-formula/src/controllers/array-formula-display.controller.tsindex a5a0f0caa4..31d0f02d78 100644--- a/packages/sheets-formula/src/controllers/array-formula-display.controller.ts+++ b/packages/sheets-formula/src/controllers/array-formula-display.controller.ts@@ -19,7 +19,6 @@ import { CellValueType, Disposable, ICommandService, LifecycleStages, OnLifecyclimport type { ISetArrayFormulaDataMutationParams } from '@univerjs/engine-formula';import { FormulaDataModel, SetArrayFormulaDataMutation } from '@univerjs/engine-formula';import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';-import { getPatternPreview } from '@univerjs/sheets-numfmt';import { Inject } from '@wendellhu/redi';@OnLifecycle(LifecycleStages.Ready, ArrayFormulaDisplayController)@@ -80,36 +79,36 @@ export class ArrayFormulaDisplayController extends Disposable {return next(cell);}- const numfmtItemMap = this._formulaDataModel.getNumfmtItemMap();- const numfmtItem = numfmtItemMap[unitId]?.[subUnitId]?.[row]?.[col];-- if (numfmtItem) {- const value = cellData?.v;- const type = cellData?.t;-- if (value == null || type !== CellValueType.NUMBER) {- return next(cell);- }-- const info = getPatternPreview(numfmtItem, value as number);-- if (info.color) {- const colorMap = this._themeService.getCurrentTheme();- const color = colorMap[`${info.color}500`];- return {- ...cell,- v: info.result,- t: CellValueType.STRING,- s: { cl: { rgb: color } },- };- }-- return {- ...cell,- v: info.result,- t: CellValueType.STRING,- };- }+ // const numfmtItemMap = this._formulaDataModel.getNumfmtItemMap();+ // const numfmtItem = numfmtItemMap[unitId]?.[subUnitId]?.[row]?.[col];++ // if (numfmtItem) {+ // const value = cellData?.v;+ // const type = cellData?.t;++ // if (value == null || type !== CellValueType.NUMBER) {+ // return next(cell);+ // }++ // const info = getPatternPreview(numfmtItem, value as number);++ // if (info.color) {+ // const colorMap = this._themeService.getCurrentTheme();+ // const color = colorMap[`${info.color}500`];+ // return {+ // ...cell,+ // v: info.result,+ // t: CellValueType.STRING,+ // s: { cl: { rgb: color } },+ // };+ // }++ // return {+ // ...cell,+ // v: info.result,+ // t: CellValueType.STRING,+ // };+ // }if (cellData.v == null && cellData.t == null) {return next({ ...cell,diff --git a/packages/sheets-formula/src/controllers/numfmt-formula-display.controller.ts b/packages/sheets-formula/src/controllers/numfmt-formula-display.controller.tsdeleted file mode 100644index 3585f3bfca..0000000000--- a/packages/sheets-formula/src/controllers/numfmt-formula-display.controller.ts+++ /dev/null@@ -1,108 +0,0 @@-/**- * Copyright 2023-present DreamNum Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { ICommandInfo } from '@univerjs/core';-import { CellValueType, Disposable, ICommandService, LifecycleStages, OnLifecycle, ThemeService } from '@univerjs/core';-import type { ISetNumfmtFormulaDataMutationParams } from '@univerjs/engine-formula';-import { FormulaDataModel, SetNumfmtFormulaDataMutation } from '@univerjs/engine-formula';-import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';-import { getPatternPreview } from '@univerjs/sheets-numfmt';-import { Inject } from '@wendellhu/redi';--@OnLifecycle(LifecycleStages.Ready, NumfmtFormulaDisplayController)-export class NumfmtFormulaDisplayController extends Disposable {- constructor(- @ICommandService private readonly _commandService: ICommandService,- @Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,- @Inject(FormulaDataModel) private readonly _formulaDataModel: FormulaDataModel,- @Inject(ThemeService) private readonly _themeService: ThemeService- ) {- super();-- this._initialize();- }-- private _initialize(): void {- this._commandExecutedListener();-- this._initInterceptorCellContent();- }-- private _commandExecutedListener() {- this.disposeWithMe(- this._commandService.onCommandExecuted((command: ICommandInfo) => {- // Synchronous data from worker- if (command.id !== SetNumfmtFormulaDataMutation.id) {- return;- }-- const params = command.params as ISetNumfmtFormulaDataMutationParams;-- if (params == null) {- return;- }-- const { numfmtItemMap } = params;- this._formulaDataModel.updateNumfmtItemMap(numfmtItemMap);- })- );- }-- private _initInterceptorCellContent() {- this.disposeWithMe(- this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {- priority: 98,- handler: (cell, location, next) => {- const { unitId, subUnitId, row, col } = location;-- const numfmtItemMap = this._formulaDataModel.getNumfmtItemMap();- const numfmtItem = numfmtItemMap[unitId]?.[subUnitId]?.[row]?.[col];- const v = next(cell);- if (numfmtItem == null || numfmtItem === '') {- return v;- }-- const rawValue = location.worksheet.getCellRaw(row, col);- const value = rawValue?.v;- const type = rawValue?.t;-- if (value == null || type !== CellValueType.NUMBER) {- return v;- }-- const info = getPatternPreview(numfmtItem, value as number);-- if (info.color) {- const colorMap = this._themeService.getCurrentTheme();- const color = colorMap[`${info.color}500`];- return {- ...v,- v: info.result,- t: CellValueType.STRING,- s: { cl: { rgb: color } },- };- }-- return {- ...v,- v: info.result,- t: CellValueType.STRING,- };- },- })- );- }-}diff --git a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts b/packages/sheets-formula/src/controllers/trigger-calculation.controller.tsindex 68719534dd..991e6227f8 100644--- a/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts+++ b/packages/sheets-formula/src/controllers/trigger-calculation.controller.ts@@ -15,12 +15,11 @@*/import type { ICommandInfo, IUnitRange } from '@univerjs/core';-import { Disposable, ICommandService, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';+import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';import type {IDirtyUnitFeatureMap,IDirtyUnitOtherFormulaMap,IDirtyUnitSheetNameMap,- INumfmtItemMap,ISetFormulaCalculationNotificationMutation } from '@univerjs/engine-formula';import {FormulaDataModel,@@ -134,7 +133,7 @@ export class TriggerCalculationController extends Disposable {const allDirtyUnitFeatureMap: IDirtyUnitFeatureMap = {};const allDirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap = {};- const numfmtItemMap: INumfmtItemMap = Tools.deepClone(this._formulaDataModel.getNumfmtItemMap());+ // const numfmtItemMap: INumfmtItemMap = Tools.deepClone(this._formulaDataModel.getNumfmtItemMap());for (const command of commands) {const conversion = this._activeDirtyManagerService.get(command.id);@@ -168,46 +167,13 @@ export class TriggerCalculationController extends Disposable {}}- // number format data- allDirtyRanges.forEach((dirtyRange) => {- const { unitId, sheetId } = dirtyRange;-- if (numfmtItemMap[unitId] == null) {- numfmtItemMap[unitId] = {};- }-- if (numfmtItemMap[unitId]![sheetId] == null) {- numfmtItemMap[unitId]![sheetId] = {};- }-- const numfmtModel = this._numfmtService.getModel(unitId, sheetId);-- if (!numfmtModel) return;-- const refMode = this._numfmtService.getRefModel(unitId);-- numfmtModel.forValue((row, col, numfmtValue) => {- if (numfmtValue && refMode) {- const refValue = refMode.getValue(numfmtValue?.i, ['i']);-- if (!refValue) return;-- if (numfmtItemMap[unitId]![sheetId][row] == null) {- numfmtItemMap[unitId]![sheetId][row] = {};- }-- numfmtItemMap[unitId]![sheetId][row][col] = refValue.pattern;- }- });- });-return {dirtyRanges: allDirtyRanges,dirtyNameMap: allDirtyNameMap,dirtyDefinedNameMap: allDirtyDefinedNameMap,dirtyUnitFeatureMap: allDirtyUnitFeatureMap,dirtyUnitOtherFormulaMap: allDirtyUnitOtherFormulaMap,- numfmtItemMap,+ // numfmtItemMap,};}diff --git a/packages/sheets-formula/src/controllers/update-formula.controller.ts b/packages/sheets-formula/src/controllers/update-formula.controller.tsindex 53142c658e..628fa617ca 100644--- a/packages/sheets-formula/src/controllers/update-formula.controller.ts+++ b/packages/sheets-formula/src/controllers/update-formula.controller.ts@@ -46,7 +46,6 @@ import { deserializeRangeWithSheet,serializeRangeToRefString,SetArrayFormulaDataMutation,SetFormulaDataMutation,- SetNumfmtFormulaDataMutation,} from '@univerjs/engine-formula';import type {@@ -227,7 +226,6 @@ export class UpdateFormulaController extends Disposable {this._formulaDataModel.updateArrayFormulaCellData(unitId, sheetId, cellValue);this._formulaDataModel.updateArrayFormulaRange(unitId, sheetId, cellValue);- this._formulaDataModel.updateNumfmtData(unitId, sheetId, cellValue); // TODO: move model to snapshotthis._commandService.executeCommand(SetFormulaDataMutation.id,@@ -250,16 +248,6 @@ export class UpdateFormulaController extends Disposable {remove: true, // remove array formula range shape});-- this._commandService.executeCommand(- SetNumfmtFormulaDataMutation.id,- {- numfmtItemMap: this._formulaDataModel.getNumfmtItemMap(),- },- {- onlyLocal: true,- }- );}private _handleRemoveSheetMutation(params: IRemoveSheetMutationParams) {diff --git a/packages/sheets-formula/src/formula-ui-plugin.ts b/packages/sheets-formula/src/formula-ui-plugin.tsindex 843823fc98..e9cda1bb52 100644--- a/packages/sheets-formula/src/formula-ui-plugin.ts+++ b/packages/sheets-formula/src/formula-ui-plugin.ts@@ -38,7 +38,6 @@ import {} from './services/formula-custom-function.service';import { FormulaPromptService, IFormulaPromptService } from './services/prompt.service';import { IRegisterFunctionService, RegisterFunctionService } from './services/register-function.service';-import { NumfmtFormulaDisplayController } from './controllers/numfmt-formula-display.controller';import { DefinedNameController } from './controllers/defined-name.controller';import { FormulaRefRangeService } from './services/formula-ref-range.service';import { RegisterOtherFormulaService } from './services/register-other-formula.service';@@ -88,7 +87,6 @@ export class UniverSheetsFormulaPlugin extends Plugin {[FormulaAutoFillController],[FormulaClipboardController],[ArrayFormulaDisplayController],- [NumfmtFormulaDisplayController],[TriggerCalculationController],[UpdateFormulaController],[FormulaEditorShowController],diff --git a/packages/sheets-numfmt/src/controllers/__tests__/auto-fill.controller.spec.ts b/packages/sheets-numfmt/src/controllers/__tests__/auto-fill.controller.spec.tsdeleted file mode 100644index a1a8303665..0000000000--- a/packages/sheets-numfmt/src/controllers/__tests__/auto-fill.controller.spec.ts+++ /dev/null@@ -1,310 +0,0 @@-/**- * Copyright 2023-present DreamNum Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { IRange, Workbook, Worksheet } from '@univerjs/core';-import { ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';-import type { ISetNumfmtMutationParams } from '@univerjs/sheets';-import { SelectionManagerService, SetNumfmtMutation } from '@univerjs/sheets';-import { APPLY_TYPE, AutoFillService, IAutoFillService } from '@univerjs/sheets-ui';-import { beforeEach, describe, expect, it } from 'vitest';--import { SHEET_NUMFMT_PLUGIN } from '../../base/const/PLUGIN_NAME';-import { NumfmtAutoFillController } from '../numfmt.auto-fill.controller';-import { NumfmtCellContent } from '../numfmt.cell-content.controller';-import { createTestBed } from './test.util';--describe('test auto fill', () => {- let unitId: string = '';- let subUnitId: string = '';- let workbook: Workbook;- let worksheet: Worksheet;- let testBed: ReturnType<typeof createTestBed>;- let commandService: ICommandService;-- beforeEach(() => {- testBed = createTestBed([- [NumfmtAutoFillController],- [NumfmtCellContent],- [SelectionManagerService],- [IAutoFillService, { useClass: AutoFillService }],- ]);- unitId = testBed.unitId;- subUnitId = testBed.subUnitId;- commandService = testBed.get(ICommandService);- const univerInstanceService = testBed.get(IUniverInstanceService);- testBed.get(NumfmtAutoFillController);- testBed.get(NumfmtCellContent);- workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;- worksheet = workbook.getActiveSheet();- });- it('test fill format ,repeat range is divisible', () => {- const params: ISetNumfmtMutationParams = {- unitId,- subUnitId,- values: {- 1: {- ranges: [{ startRow: 0, endRow: 5, startColumn: 0, endColumn: 5 }],- },- },- refMap: {- 1: {- pattern: '$#,##0;(#,##0)',- type: '' as any,- },- },- };- commandService.syncExecuteCommand(SetNumfmtMutation.id, params);- const autoFillService = testBed.get(IAutoFillService);- const hooks = autoFillService.getAllHooks();- const item = hooks.find((ele) => ele.id === SHEET_NUMFMT_PLUGIN)!;- expect(!!item).toBeTruthy();- const source: IRange = {- startRow: 3,- endRow: 5,- startColumn: 0,- endColumn: 1,- };- const target: IRange = {- startRow: 3,- endRow: 5,- startColumn: 2,- endColumn: 9,- };- const result =- item.onFillData &&- item.onFillData({ source, target, unitId, subUnitId }, '' as any, APPLY_TYPE.ONLY_FORMAT);- expect(result).toEqual({- undos: [- {- id: 'sheet.mutation.remove.numfmt',- params: {- ranges: [- {- startRow: 3,- endRow: 5,- startColumn: 6,- endColumn: 9,- },- ],- unitId: 'test',- subUnitId: 'sheet1',- },- },- {- id: 'sheet.mutation.set.numfmt',- params: {- values: {- 1: {- ranges: [- {- startRow: 3,- endRow: 5,- startColumn: 2,- endColumn: 5,- },- ],- },- },- refMap: {- 1: {- pattern: '$#,##0;(#,##0)',- type: '',- },- },- unitId: 'test',- subUnitId: 'sheet1',- },- },- ],- redos: [- {- id: 'sheet.mutation.set.numfmt',- params: {- values: {- 1: {- ranges: [- {- startRow: 3,- endRow: 5,- startColumn: 2,- endColumn: 9,- },- ],- },- },- refMap: {- 1: {- pattern: '$#,##0;(#,##0)',- type: '',- },- },- unitId: 'test',- subUnitId: 'sheet1',- },- },- ],- });- });- // @TODO:YuHong,there are some repeat problems to be solved- it('test fill format ,repeat range is not divisible', () => {- const params: ISetNumfmtMutationParams = {- unitId,- subUnitId,- values: {- 1: {- ranges: [{ startRow: 0, endRow: 5, startColumn: 0, endColumn: 5 }],- },- },- refMap: {- 1: {- pattern: '$#,##0;(#,##0)',- type: '' as any,- },- },- };- commandService.syncExecuteCommand(SetNumfmtMutation.id, params);- const autoFillService = testBed.get(IAutoFillService);- const hooks = autoFillService.getAllHooks();- const item = hooks.find((ele) => ele.id === SHEET_NUMFMT_PLUGIN)!;- expect(!!item).toBeTruthy();- const source: IRange = {- startRow: 3,- endRow: 5,- startColumn: 0,- endColumn: 1,- };- const target: IRange = {- startRow: 3,- endRow: 5,- startColumn: 2,- endColumn: 10,- };- const result =- item.onFillData &&- item.onFillData({ source, target, unitId, subUnitId }, '' as any, APPLY_TYPE.ONLY_FORMAT);- expect(result).toEqual({- undos: [- {- id: 'sheet.mutation.remove.numfmt',- params: {- ranges: [- {- startRow: 3,- endRow: 5,- startColumn: 6,- endColumn: 10,- },- ],- unitId: 'test',- subUnitId: 'sheet1',- },- },- {- id: 'sheet.mutation.set.numfmt',- params: {- values: {- 1: {- ranges: [- {- startRow: 3,- endRow: 5,- startColumn: 2,- endColumn: 5,- },- ],- },- },- refMap: {- 1: {- pattern: '$#,##0;(#,##0)',- type: '',- },- },- unitId: 'test',- subUnitId: 'sheet1',- },- },- ],- redos: [- {- id: 'sheet.mutation.set.numfmt',- params: {- values: {- 1: {- ranges: [- {- startRow: 3,- endRow: 5,- startColumn: 2,- endColumn: 10,- },- ],- },- },- refMap: {- 1: {- pattern: '$#,##0;(#,##0)',- type: '',- },- },- unitId: 'test',- subUnitId: 'sheet1',- },- },- ],- });- });- it('test fill without format', () => {- const params: ISetNumfmtMutationParams = {- unitId,- subUnitId,- values: {- 1: {- ranges: [{ startRow: 0, endRow: 5, startColumn: 0, endColumn: 5 }],- },- },- refMap: {- 1: {- pattern: '$#,##0;(#,##0)',- type: '' as any,- },- },- };- commandService.syncExecuteCommand(SetNumfmtMutation.id, params);- const autoFillService = testBed.get(IAutoFillService);- const hooks = autoFillService.getAllHooks();- const item = hooks.find((ele) => ele.id === SHEET_NUMFMT_PLUGIN)!;- expect(!!item).toBeTruthy();- const source: IRange = {- startRow: 3,- endRow: 5,- startColumn: 0,- endColumn: 1,- };- const target: IRange = {- startRow: 3,- endRow: 5,- startColumn: 2,- endColumn: 10,- };- const result =- item.onFillData && item.onFillData({ source, target, unitId, subUnitId }, '' as any, APPLY_TYPE.NO_FORMAT);- expect(result).toEqual({- undos: [],- redos: [],- });- });-});diff --git a/packages/sheets-numfmt/src/controllers/__tests__/cell-content.controller.spec.ts b/packages/sheets-numfmt/src/controllers/__tests__/cell-content.controller.spec.tsindex 17be4b1f5a..413361b9ab 100644--- a/packages/sheets-numfmt/src/controllers/__tests__/cell-content.controller.spec.ts+++ b/packages/sheets-numfmt/src/controllers/__tests__/cell-content.controller.spec.ts@@ -49,7 +49,6 @@ describe('test cell-content', () => {refMap: {1: {pattern: '$#,##0;(#,##0)',- type: '' as any,},},};@@ -62,9 +61,10 @@ describe('test cell-content', () => {const startTimeWithNumfmt = performance.now();const value1 = worksheet.getCell(0, 0);const timeWithNumfmt = performance.now() - startTimeWithNumfmt;- expect(value1).toEqual({ v: '$0', t: 2 });+ expect(value1!.v).toEqual('$0');+ expect(value1!.t).toEqual(2);+const startTimeWithNumfmtCache = performance.now();- const value2 = worksheet.getCell(0, 0);const timeWithNumfmtCache = performance.now() - startTimeWithNumfmtCache;// With caching, it takes less time than without caching// console.log(timeWithNumfmtCache, ' ', timeWithNumfmt);diff --git a/packages/sheets-numfmt/src/controllers/__tests__/copy-paste.controller.spec.ts b/packages/sheets-numfmt/src/controllers/__tests__/copy-paste.controller.spec.tsdeleted file mode 100644index 92bbe12d2c..0000000000--- a/packages/sheets-numfmt/src/controllers/__tests__/copy-paste.controller.spec.ts+++ /dev/null@@ -1,216 +0,0 @@-/**- * Copyright 2023-present DreamNum Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import { ICommandService } from '@univerjs/core';-import type { ISetNumfmtMutationParams } from '@univerjs/sheets';-import { SetNumfmtMutation } from '@univerjs/sheets';-import type { ISheetClipboardHook } from '@univerjs/sheets-ui';-import { ISheetClipboardService } from '@univerjs/sheets-ui';-import { beforeEach, describe, expect, it } from 'vitest';--import { SHEET_NUMFMT_PLUGIN } from '../../base/const/PLUGIN_NAME';-import { NumfmtCopyPasteController } from '../numfmt.copy-paste.controller';-import { createTestBed } from './test.util';--class MockSheetClipboardService {- hooks: ISheetClipboardHook[] = [];- getHooks = () => this.hooks;- addClipboardHook = (config: ISheetClipboardHook) => {- this.hooks.push(config);- };-}-describe('test copy paste', () => {- let unitId: string = '';- let subUnitId: string = '';- let testBed: any;- let commandService: ICommandService;- beforeEach(() => {- testBed = createTestBed([- [NumfmtCopyPasteController],- [ISheetClipboardService, { useClass: MockSheetClipboardService }],- ]);- unitId = testBed.unitId;- subUnitId = testBed.subUnitId;- testBed.get(NumfmtCopyPasteController);- commandService = testBed.get(ICommandService);- });- it('test', () => {- const params: ISetNumfmtMutationParams = {- unitId,- subUnitId,- values: {- 1: {- ranges: [{ startRow: 0, endRow: 3, startColumn: 0, endColumn: 4 }],- },- },- refMap: {- 1: {- pattern: '$#,##0;(#,##0)',- type: '' as any,- },- },- };- commandService.syncExecuteCommand(SetNumfmtMutation.id, params);- const sheetClipboardService = testBed.get(ISheetClipboardService) as MockSheetClipboardService;- const hooks = sheetClipboardService.getHooks();- const hook = hooks.find((hook) => hook.id === SHEET_NUMFMT_PLUGIN)!;- expect(!!hook).toBeTruthy();- hook.onBeforeCopy!(unitId, subUnitId, {- startRow: 2,- startColumn: 3,- endRow: 4,- endColumn: 4,- });- const result = hook.onPasteCells!(- {- unitId,- subUnitId,- range: {- startRow: 2,- startColumn: 3,- endRow: 4,- endColumn: 4,- },- },- {- range: {- startRow: 9,- startColumn: 5,- endRow: 11,- endColumn: 6,- rangeType: 0,- },- unitId,- subUnitId,- },- {- 0: {- 0: {- p: null,- v: 5,- s: null,- f: null,- si: null,- t: 2,- },- 1: {- p: null,- v: 6,- s: null,- f: null,- si: null,- t: 2,- },- },- 1: {- 0: {- p: null,- v: 6,- s: null,- f: null,- si: null,- t: 2,- },- 1: {- p: null,- v: 7,- s: null,- f: null,- si: null,- t: 2,- },- },- 2: {- 0: {- p: null,- v: 7,- s: null,- f: null,- si: null,- t: 2,- },- 1: {- p: null,- v: 8,- s: null,- f: null,- si: null,- t: 2,- },- },- } as any,- {- copyType: 'COPY',- copyId: 'asdasd',- pasteType: 'default-paste',- } as any- );- expect(result).toEqual({- redos: [- {- id: 'sheet.mutation.remove.numfmt',- params: {- unitId,- subUnitId,- ranges: [],- },- },- {- id: 'sheet.mutation.set.numfmt',- params: {- unitId,- subUnitId,- refMap: {- 0: {- pattern: '$#,##0;(#,##0)',- type: '',- },- },- values: {- 0: {- ranges: [- {- startRow: 9,- endRow: 10,- startColumn: 5,- endColumn: 6,- },- ],- },- },- },- },- ],- undos: [- {- id: 'sheet.mutation.remove.numfmt',- params: {- ranges: [- {- startRow: 9,- endRow: 10,- startColumn: 5,- endColumn: 6,- },- ],- unitId,- subUnitId,- },- },- ],- });- });-});diff --git a/packages/sheets-numfmt/src/controllers/__tests__/editor.controller.spec.ts b/packages/sheets-numfmt/src/controllers/__tests__/editor.controller.spec.tsindex 5d3d2c537f..62a44e22a5 100644--- a/packages/sheets-numfmt/src/controllers/__tests__/editor.controller.spec.ts+++ b/packages/sheets-numfmt/src/controllers/__tests__/editor.controller.spec.ts@@ -69,7 +69,6 @@ describe('test editor', () => {refMap: {1: {pattern: '$#,##0;(#,##0)',- type: '' as any,},},};@@ -84,12 +83,15 @@ describe('test editor', () => {col: 0,};const cellData = worksheet.getCell(0, 0);- expect(cellData).toEqual({ v: '$0', t: 2 });+ expect(cellData!.v).toEqual('$0');+ expect(cellData!.t).toEqual(2);+const result = editorBridgeService.interceptor.fetchThroughInterceptors(editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT)(cellData, location);// The currency format needs to be entered in the editor with real values, not with currency symbols- expect(result).toEqual({ v: 0, t: 2 });+ expect(result!.v).toEqual(0);+ expect(result!.t).toEqual(2);});it('before edit with data', () => {const params: ISetNumfmtMutationParams = {@@ -103,7 +105,6 @@ describe('test editor', () => {refMap: {1: {pattern: 'A/P h:mm:ss',- type: '' as any,},},};@@ -136,7 +137,6 @@ describe('test editor', () => {refMap: {1: {pattern: 'h:mm:ss',- type: '' as any,},},};diff --git a/packages/sheets-numfmt/src/controllers/numfmt.auto-fill.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.auto-fill.controller.tsdeleted file mode 100644index 6579b45106..0000000000--- a/packages/sheets-numfmt/src/controllers/numfmt.auto-fill.controller.ts+++ /dev/null@@ -1,152 +0,0 @@-/**- * Copyright 2023-present DreamNum Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { IMutationInfo, IRange, Workbook } from '@univerjs/core';-import { Disposable, IUniverInstanceService, LifecycleStages, OnLifecycle, Range, Rectangle, UniverInstanceType } from '@univerjs/core';-import type { ISetCellsNumfmt, ISetNumfmtMutationParams } from '@univerjs/sheets';-import {- factorySetNumfmtUndoMutation,- INumfmtService,- SetNumfmtMutation,- transformCellsToRange,-} from '@univerjs/sheets';-import type { ISheetAutoFillHook } from '@univerjs/sheets-ui';-import { APPLY_TYPE, getAutoFillRepeatRange, IAutoFillService } from '@univerjs/sheets-ui';-import { Inject, Injector } from '@wendellhu/redi';--import { SHEET_NUMFMT_PLUGIN } from '../base/const/PLUGIN_NAME';-import { mergeNumfmtMutations } from '../utils/mutation';--@OnLifecycle(LifecycleStages.Rendered, NumfmtAutoFillController)-export class NumfmtAutoFillController extends Disposable {- constructor(- @Inject(Injector) private _injector: Injector,- @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,- @Inject(INumfmtService) private _numfmtService: INumfmtService,- @Inject(IAutoFillService) private _autoFillService: IAutoFillService- ) {- super();-- this._initAutoFill();- }-- private _initAutoFill() {- const noopReturnFunc = () => ({ redos: [], undos: [] });- const loopFunc = (- sourceStartCell: { row: number; col: number },- targetStartCell: { row: number; col: number },- relativeRange: IRange- ) => {- const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;- const unitId = workbook.getUnitId();- const subUnitId = workbook.getActiveSheet().getSheetId();- const sourceRange = {- startRow: sourceStartCell.row,- startColumn: sourceStartCell.col,- endColumn: sourceStartCell.col,- endRow: sourceStartCell.row,- };- const targetRange = {- startRow: targetStartCell.row,- startColumn: targetStartCell.col,- endColumn: targetStartCell.col,- endRow: targetStartCell.row,- };-- const values: ISetCellsNumfmt = [];-- Range.foreach(relativeRange, (row, col) => {- const sourcePositionRange = Rectangle.getPositionRange(- {- startRow: row,- startColumn: col,- endColumn: col,- endRow: row,- },- sourceRange- );- const oldNumfmtValue = this._numfmtService.getValue(- unitId,- subUnitId,- sourcePositionRange.startRow,- sourcePositionRange.startColumn- );- if (oldNumfmtValue) {- const targetPositionRange = Rectangle.getPositionRange(- {- startRow: row,- startColumn: col,- endColumn: col,- endRow: row,- },- targetRange- );- values.push({- pattern: oldNumfmtValue.pattern,- type: oldNumfmtValue.type,- row: targetPositionRange.startRow,- col: targetPositionRange.startColumn,- });- }- });- if (values.length) {- const redo: IMutationInfo<ISetNumfmtMutationParams> = {- id: SetNumfmtMutation.id,- params: transformCellsToRange(unitId, subUnitId, values),- };- const undos = factorySetNumfmtUndoMutation(this._injector, redo.params);- return {- redos: [redo],- undos,- };- }- return { redos: [], undos: [] };- };- const generalApplyFunc = (sourceRange: IRange, targetRange: IRange) => {- const totalUndos: IMutationInfo[] = [];- const totalRedos: IMutationInfo[] = [];- const sourceStartCell = {- row: sourceRange.startRow,- col: sourceRange.startColumn,- };- const repeats = getAutoFillRepeatRange(sourceRange, targetRange);- repeats.forEach((repeat) => {- const { undos, redos } = loopFunc(sourceStartCell, repeat.repeatStartCell, repeat.relativeRange);- totalUndos.push(...undos);- totalRedos.push(...redos);- });- return {- undos: mergeNumfmtMutations(totalUndos),- redos: mergeNumfmtMutations(totalRedos),- };- };- const hook: ISheetAutoFillHook = {- id: SHEET_NUMFMT_PLUGIN,- onFillData: (location, direction, applyType) => {- if (- applyType === APPLY_TYPE.COPY ||- applyType === APPLY_TYPE.ONLY_FORMAT ||- applyType === APPLY_TYPE.SERIES- ) {- const { source, target } = location;- return generalApplyFunc(source, target);- }- return noopReturnFunc();- },- };- this.disposeWithMe(this._autoFillService.addHook(hook));- }-}diff --git a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.controller.tsindex 1ef4605d62..49941890c3 100644--- a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts+++ b/packages/sheets-numfmt/src/controllers/numfmt.controller.ts@@ -30,14 +30,10 @@ import {UniverInstanceType,} from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';-import type { IRemoveNumfmtMutationParams, ISetNumfmtMutationParams } from '@univerjs/sheets';+import type { ISetNumfmtMutationParams } from '@univerjs/sheets';import {- ClearSelectionAllCommand,- ClearSelectionFormatCommand,- factoryRemoveNumfmtUndoMutation,INTERCEPTOR_POINT,INumfmtService,- rangeMerge,RemoveNumfmtMutation,SelectionManagerService,SetNumfmtMutation,@@ -45,7 +41,7 @@ import {} from '@univerjs/sheets';import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';import { ComponentManager, ISidebarService } from '@univerjs/ui';-import { Inject, Injector } from '@wendellhu/redi';+import { Inject } from '@wendellhu/redi';import { combineLatest, merge, Observable } from 'rxjs';import { debounceTime, map, switchMap, tap } from 'rxjs/operators';@@ -75,7 +71,6 @@ export class NumfmtController extends Disposable implements INumfmtController {constructor(@Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,@Inject(ThemeService) private _themeService: ThemeService,- @Inject(Injector) private _injector: Injector,@Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,@Inject(SheetSkeletonManagerService) private _sheetSkeletonManagerService: SheetSkeletonManagerService,@Inject(ICommandService) private _commandService: ICommandService,@@ -87,7 +82,6 @@ export class NumfmtController extends Disposable implements INumfmtController {@Inject(LocaleService) private _localeService: LocaleService) {super();- this._initInterceptorCommands();this._initRealTimeRenderingInterceptor();this._initPanel();this._initCommands();@@ -186,56 +180,6 @@ export class NumfmtController extends Disposable implements INumfmtController {this._componentManager.register(SHEET_NUMFMT_PLUGIN, SheetNumfmtPanel);}- private _initInterceptorCommands() {- const self = this;- this.disposeWithMe(- this._sheetInterceptorService.interceptCommand({- getMutations(command) {- switch (command.id) {- case ClearSelectionAllCommand.id:- case ClearSelectionFormatCommand.id: {- const workbook = self._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;- const unitId = workbook.getUnitId();- const subUnitId = workbook.getActiveSheet().getSheetId();- const selections = self._selectionManagerService.getSelectionRanges();- if (!selections?.length) {- break;- }- const redos: IRemoveNumfmtMutationParams = {- unitId,- subUnitId,- ranges: [],- };- const numfmtModel = self._numfmtService.getModel(unitId, subUnitId);- selections.forEach((range) => {- Range.foreach(range, (row, col) => {- if (numfmtModel?.getValue(row, col)) {- redos.ranges.push({- startColumn: col,- endColumn: col,- startRow: row,- endRow: row,- });- }- });- });- redos.ranges = rangeMerge(redos.ranges);- const undos = factoryRemoveNumfmtUndoMutation(self._injector, redos);- return {- redos: [{ id: RemoveNumfmtMutation.id, params: redos }],- undos,- };- }- }- return {- redos: [],- undos: [],- };- },- })- );- }-private _initRealTimeRenderingInterceptor() {const isPanelOpenObserver = new Observable<boolean>((subscribe) => {this._commandService.onCommandExecuted((commandInfo) => {@@ -352,8 +296,7 @@ export class NumfmtController extends Disposable implements INumfmtController {return () => {disposable.dispose();};- }),- this._numfmtService.modelReplace$+ })).pipe(debounceTime(16)).subscribe((unitId) => {diff --git a/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.tsdeleted file mode 100644index 7cb7a841da..0000000000--- a/packages/sheets-numfmt/src/controllers/numfmt.copy-paste.controller.ts+++ /dev/null@@ -1,247 +0,0 @@-/**- * Copyright 2023-present DreamNum Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { IRange, Nullable, Workbook } from '@univerjs/core';-import {- Disposable,- IUniverInstanceService,- LifecycleStages,- ObjectMatrix,- OnLifecycle,- Range,- Rectangle,- UniverInstanceType,-} from '@univerjs/core';-import type { FormatType, IRemoveNumfmtMutationParams, ISetCellsNumfmt } from '@univerjs/sheets';-import {- factoryRemoveNumfmtUndoMutation,- factorySetNumfmtUndoMutation,- INumfmtService,- rangeMerge,- RemoveNumfmtMutation,- SetNumfmtMutation,- transformCellsToRange,-} from '@univerjs/sheets';-import type { ICellDataWithSpanInfo } from '@univerjs/sheets-ui';-import { COPY_TYPE, getRepeatRange, ISheetClipboardService, PREDEFINED_HOOK_NAME } from '@univerjs/sheets-ui';-import { Inject, Injector } from '@wendellhu/redi';--import numfmt from '@univerjs/engine-numfmt';-import { SHEET_NUMFMT_PLUGIN } from '../base/const/PLUGIN_NAME';-import { mergeNumfmtMutations } from '../utils/mutation';--@OnLifecycle(LifecycleStages.Rendered, NumfmtCopyPasteController)-export class NumfmtCopyPasteController extends Disposable {- private _copyInfo: Nullable<{- matrix: ObjectMatrix<{ pattern: string; type: FormatType }>;- info: {- unitId: string;- subUnitId: string;- };- }>;-- constructor(- @Inject(ISheetClipboardService) private _sheetClipboardService: ISheetClipboardService,- @Inject(Injector) private _injector: Injector,- @Inject(INumfmtService) private _numfmtService: INumfmtService,- @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService- ) {- super();- this._initClipboardHook();- }-- private _initClipboardHook() {- this.disposeWithMe(- this._sheetClipboardService.addClipboardHook({- id: SHEET_NUMFMT_PLUGIN,- onBeforeCopy: (unitId, subUnitId, range) => this._collectNumfmt(unitId, subUnitId, range),- onPasteCells: (pasteFrom, pasteTo, data, payload) => {- const { copyType = COPY_TYPE.COPY, pasteType } = payload;- const { range: copyRange } = pasteFrom || {};- const { range: pastedRange } = pasteTo;- const res = this._generateNumfmtMutations(pastedRange, { copyType, pasteType, copyRange, data });- return res;- },- })- );- }-- private _collectNumfmt(unitId: string, subUnitId: string, range: IRange) {- const matrix = new ObjectMatrix<{ pattern: string; type: FormatType }>();- this._copyInfo = {- matrix,- info: {- unitId,- subUnitId,- },- };- const model = this._numfmtService.getModel(unitId, subUnitId);- if (!model) {- return;- }- Range.foreach(range, (row, col) => {- const numfmtValue = this._numfmtService.getValue(unitId, subUnitId, row, col, model);- if (!numfmtValue) {- return;- }- const relativeRange = Rectangle.getRelativeRange(- {- startRow: row,- endRow: row,- startColumn: col,- endColumn: col,- },- range- );- matrix.setValue(relativeRange.startRow, relativeRange.startColumn, {- pattern: numfmtValue.pattern,- type: numfmtValue.type,- });- });- }-- private _generateNumfmtMutations(- pastedRange: IRange,- copyInfo: {- copyType: COPY_TYPE;- copyRange?: IRange;- pasteType: string;- data: ObjectMatrix<ICellDataWithSpanInfo>;- }- ) {- const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;- const sheet = workbook.getActiveSheet();- const unitId = workbook.getUnitId();- const subUnitId = sheet.getSheetId();- const numfmtModel = this._numfmtService.getModel(unitId, subUnitId);- if (copyInfo.copyType === COPY_TYPE.CUT) {- // This do not need to deal with clipping.- // move range had handle this case .- // to see numfmt.ref-range.controller.ts- this._copyInfo = null;- return { redos: [], undos: [] };- }- if (!copyInfo.copyRange && copyInfo.data) {- const removeRedos: IRemoveNumfmtMutationParams = { unitId, subUnitId, ranges: [] };- const cells: ISetCellsNumfmt = [];- Range.foreach(pastedRange, (row, col) => {- if (this._numfmtService.getValue(unitId, subUnitId, row, col, numfmtModel!)) {- removeRedos.ranges.push({ startRow: row, startColumn: col, endRow: row, endColumn: col });- }- });- copyInfo.data.forValue((row, col, value) => {- const content = String(value.v);-- const dateInfo = numfmt.parseDate(content) || numfmt.parseTime(content) || numfmt.parseNumber(content);- const isTranslateDate = !!dateInfo;- if (isTranslateDate) {- if (dateInfo && dateInfo.z) {- cells.push({- row: pastedRange.startRow + row,- col: pastedRange.startColumn + col,- pattern: dateInfo.z || '',- type: 'date',- });- }- }- });- const setRedos = transformCellsToRange(unitId, subUnitId, cells);- Object.keys(setRedos.values).forEach((key) => {- const v = setRedos.values[key];- v.ranges = rangeMerge(v.ranges);- });-- removeRedos.ranges = rangeMerge(removeRedos.ranges);- const undos = [- ...factorySetNumfmtUndoMutation(this._injector, setRedos),- ...factoryRemoveNumfmtUndoMutation(this._injector, removeRedos),- ];-- return {- redos: [- { id: RemoveNumfmtMutation.id, params: removeRedos },- { id: SetNumfmtMutation.id, params: setRedos },- ],- undos: mergeNumfmtMutations(undos),- };- }-- if (!this._copyInfo || !this._copyInfo.matrix.getSizeOf() || !copyInfo.copyRange) {- return { redos: [], undos: [] };- }-- if (- [PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH, PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE].includes(- copyInfo.pasteType- )- ) {- return { redos: [], undos: [] };- }-- const repeatRange = getRepeatRange(copyInfo.copyRange, pastedRange, true);- const cells: ISetCellsNumfmt = [];- const removeRedos: IRemoveNumfmtMutationParams = { unitId, subUnitId, ranges: [] };-- // Clears the destination area data format- Range.foreach(pastedRange, (row, col) => {- if (this._numfmtService.getValue(unitId, subUnitId, row, col, numfmtModel!)) {- removeRedos.ranges.push({ startRow: row, startColumn: col, endRow: row, endColumn: col });- }- });-- // Set up according to the data collected. This will overlap with the cleanup, but that's okay- repeatRange.forEach((item) => {- this._copyInfo &&- this._copyInfo.matrix.forValue((row, col, value) => {- const range = Rectangle.getPositionRange(- {- startRow: row,- endRow: row,- startColumn: col,- endColumn: col,- },- item.startRange- );- cells.push({- row: range.startRow,- col: range.startColumn,- pattern: value.pattern,- type: value.type,- });- });- });- const setRedos = transformCellsToRange(unitId, subUnitId, cells);-- Object.keys(setRedos.values).forEach((key) => {- const v = setRedos.values[key];- v.ranges = rangeMerge(v.ranges);- });-- removeRedos.ranges = rangeMerge(removeRedos.ranges);- const undos = [- ...factorySetNumfmtUndoMutation(this._injector, setRedos),- ...factoryRemoveNumfmtUndoMutation(this._injector, removeRedos),- ];-- return {- redos: [- { id: RemoveNumfmtMutation.id, params: removeRedos },- { id: SetNumfmtMutation.id, params: setRedos },- ],- undos: mergeNumfmtMutations(undos),- };- }-}diff --git a/packages/sheets-numfmt/src/controllers/numfmt.editor.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.editor.controller.tsindex 90945ddfcf..5bcb86b8bd 100644--- a/packages/sheets-numfmt/src/controllers/numfmt.editor.controller.ts+++ b/packages/sheets-numfmt/src/controllers/numfmt.editor.controller.ts@@ -147,6 +147,7 @@ export class NumfmtEditorController extends Disposable {context.row,context.col);+ const currentNumfmtType = (currentNumfmtValue && getPatternType(currentNumfmtValue.pattern)) ?? '';const clean = () => {currentNumfmtValue &&this._collectEffectMutation.add(@@ -174,14 +175,13 @@ export class NumfmtEditorController extends Disposable {context.row,context.col,{- type: 'date',pattern: dateInfo.z,});return { ...value, v, t: CellValueType.NUMBER };}} else if (- ['date', 'time', 'datetime'].includes(currentNumfmtValue?.type || '') ||+ ['date', 'time', 'datetime'].includes(currentNumfmtType) ||!isNumeric(content)) {clean();@@ -217,7 +217,6 @@ export class NumfmtEditorController extends Disposable {row: item.row,col: item.col,pattern: item.value!.pattern,- type: item.value!.type,}));const removeCells: IRange[] = list.filter((item) => !item.value?.pattern)@@ -265,17 +264,6 @@ export class NumfmtEditorController extends Disposable {}}-const filterAtr = (obj: Record<string, any>, filterKey: string[]) => {- const keys = Object.keys(obj).filter((key) => !filterKey.includes(key));- return keys.reduce(- (pre, cur) => {- pre[cur] = obj[cur];- return pre;- },- {} as Record<string, any>- );-};-function isNumeric(str: string) {return /^-?\d+(\.\d+)?$/.test(str);}diff --git a/packages/sheets-numfmt/src/controllers/numfmt.ref-range.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.ref-range.controller.tsdeleted file mode 100644index 1a3fa8515a..0000000000--- a/packages/sheets-numfmt/src/controllers/numfmt.ref-range.controller.ts+++ /dev/null@@ -1,322 +0,0 @@-/**- * Copyright 2023-present DreamNum Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { IMutationInfo, IRange, Workbook } from '@univerjs/core';-import {- Disposable,- DisposableCollection,- ICommandService,- IUniverInstanceService,- LifecycleStages,- OnLifecycle,- Range,- toDisposable,- UniverInstanceType,-} from '@univerjs/core';-import type {- EffectRefRangeParams,- IOperator,- IRemoveNumfmtMutationParams,- ISetCellsNumfmt,- ISetNumfmtMutationParams,-} from '@univerjs/sheets';-import {- EffectRefRangId,- factoryRemoveNumfmtUndoMutation,- factorySetNumfmtUndoMutation,- handleDeleteRangeMoveLeft,- handleDeleteRangeMoveUp,- handleInsertCol,- handleInsertRangeMoveDown,- handleInsertRangeMoveRight,- handleInsertRow,- handleIRemoveCol,- handleIRemoveRow,- handleMoveCols,- handleMoveRange,- handleMoveRows,- INumfmtService,- RefRangeService,- RemoveNumfmtMutation,- runRefRangeMutations,- SetNumfmtMutation,- transformCellsToRange,-} from '@univerjs/sheets';-import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';-import type { IDisposable } from '@wendellhu/redi';-import { Inject, Injector } from '@wendellhu/redi';-import { merge, Observable } from 'rxjs';-import { bufferTime, distinctUntilChanged, filter, map, switchMap } from 'rxjs/operators';--import { mergeNumfmtMutations } from '../utils/mutation';--const numfmtMutation = [SetNumfmtMutation.id, RemoveNumfmtMutation.id];-@OnLifecycle(LifecycleStages.Rendered, NumfmtRefRangeController)-export class NumfmtRefRangeController extends Disposable {- constructor(- @Inject(INumfmtService) private _numfmtService: INumfmtService,- @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,- @Inject(Injector) private _injector: Injector,- @Inject(RefRangeService) private _refRangeService: RefRangeService,- @Inject(SheetSkeletonManagerService) private _sheetSkeletonManagerService: SheetSkeletonManagerService,- @Inject(ICommandService) private _commandService: ICommandService- ) {- super();- this._registerRefRange();- this._mergeRefMutations();- }-- private _mergeRefMutations() {- this._refRangeService.interceptor.intercept(this._refRangeService.interceptor.getInterceptPoints().MERGE_REDO, {- handler: (list, _c, next) => {- if (!list) {- return next(list);- }- const result = list.filter((item) => !numfmtMutation.includes(item.id));- result.push(...mergeNumfmtMutations(list));- return next(result);- },- });- }-- private _registerRefRange() {- this.disposeWithMe(- toDisposable(- merge(- this._sheetSkeletonManagerService.currentSkeleton$.pipe(- map((skeleton) => skeleton?.sheetId),- distinctUntilChanged()- ),- this._numfmtService.modelReplace$- )- .pipe(- switchMap(- () =>- new Observable<DisposableCollection>((subscribe) => {- const disposableCollection = new DisposableCollection();- subscribe.next(disposableCollection);- return () => {- disposableCollection.dispose();- };- })- )- )- .subscribe((disposableCollection) => {- const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;- const unitId = workbook.getUnitId();- const subUnitId = workbook.getActiveSheet().getSheetId();- const model = this._numfmtService.getModel(unitId, subUnitId);- const disposableMap: Map<string, IDisposable> = new Map();- const register = (commandInfo: EffectRefRangeParams, row: number, col: number) => {- const targetRange = {- startRow: row,- startColumn: col,- endRow: row,- endColumn: col,- };- let operators: IOperator[] = [];- switch (commandInfo.id) {- case EffectRefRangId.DeleteRangeMoveLeftCommandId: {- operators = handleDeleteRangeMoveLeft(commandInfo, targetRange);- break;- }- case EffectRefRangId.DeleteRangeMoveUpCommandId: {- operators = handleDeleteRangeMoveUp(commandInfo, targetRange);- break;- }- case EffectRefRangId.InsertColCommandId: {- operators = handleInsertCol(commandInfo, targetRange);- break;- }- case EffectRefRangId.InsertRangeMoveDownCommandId: {- operators = handleInsertRangeMoveDown(commandInfo, targetRange);- break;- }- case EffectRefRangId.InsertRangeMoveRightCommandId: {- operators = handleInsertRangeMoveRight(commandInfo, targetRange);- break;- }- case EffectRefRangId.InsertRowCommandId: {- operators = handleInsertRow(commandInfo, targetRange);- break;- }- case EffectRefRangId.MoveRangeCommandId: {- operators = handleMoveRange(commandInfo, targetRange);- break;- }- case EffectRefRangId.RemoveColCommandId: {- operators = handleIRemoveCol(commandInfo, targetRange);- break;- }- case EffectRefRangId.RemoveRowCommandId: {- operators = handleIRemoveRow(commandInfo, targetRange);- break;- }- case EffectRefRangId.MoveColsCommandId: {- operators = handleMoveCols(commandInfo, targetRange);- break;- }- case EffectRefRangId.MoveRowsCommandId: {- operators = handleMoveRows(commandInfo, targetRange);- }- }- const resultRange = runRefRangeMutations(operators, targetRange);-- const numfmtValue = this._numfmtService.getValue(unitId, subUnitId, row, col);- if (!resultRange && numfmtValue) {- const removeRedo = {- id: RemoveNumfmtMutation.id,- params: {- unitId,- subUnitId,- ranges: [{ startColumn: col, startRow: row, endColumn: col, endRow: row }],- },- };- const undoRemove = factoryRemoveNumfmtUndoMutation(this._injector, removeRedo.params);- return {- redos: [removeRedo],- undos: undoRemove,- };- }- if (numfmtValue && resultRange) {- const redos: Array<- IMutationInfo<IRemoveNumfmtMutationParams | ISetNumfmtMutationParams>- > = [];- const undos: Array<- IMutationInfo<IRemoveNumfmtMutationParams | ISetNumfmtMutationParams>- > = [];- const setRedoCells: ISetCellsNumfmt = [- {- pattern: numfmtValue.pattern,- type: numfmtValue.type,- row: resultRange.startRow,- col: resultRange.startColumn,- },- ];- const setRedo = {- id: SetNumfmtMutation.id,- params: transformCellsToRange(unitId, subUnitId, setRedoCells),- };- const undoSet = factorySetNumfmtUndoMutation(this._injector, setRedo.params);-- const removeRedo = {- id: RemoveNumfmtMutation.id,- params: {- unitId,- subUnitId,- ranges: [{ startColumn: col, startRow: row, endColumn: col, endRow: row }],- },- };- const undoRemove = factoryRemoveNumfmtUndoMutation(this._injector, removeRedo.params);- redos.push(setRedo, removeRedo);- undos.push(...undoSet, ...undoRemove);-- return {- redos,- undos: undos.reverse(),- };- }- return { redos: [], undos: [] };- };-- model &&- model.forValue((row, col) => {- const targetRange = {- startRow: row,- startColumn: col,- endRow: row,- endColumn: col,- };- const disposable = this._refRangeService.registerRefRange(targetRange, (commandInfo) =>- register(commandInfo, row, col)- );- disposableMap.set(`${row}_${col}`, disposable);- disposableCollection.add(disposable);- });-- // on change- disposableCollection.add(- toDisposable(- new Observable<ISetNumfmtMutationParams & IRemoveNumfmtMutationParams>((subscribe) => {- disposableCollection.add(- this._commandService.onCommandExecuted((commandInfo) => {- if (- [SetNumfmtMutation.id, RemoveNumfmtMutation.id].includes(commandInfo.id)- ) {- subscribe.next(commandInfo.params as any);- }- })- );- })- .pipe(- filter(- (commandInfo) =>- commandInfo.unitId === unitId && commandInfo.subUnitId === subUnitId- ),- map((commandInfo) => {- if (commandInfo.ranges) {- return commandInfo.ranges;- }- if (commandInfo.values) {- return Object.keys(commandInfo.values).reduce((list, key) => {- const v = commandInfo.values[key];- list.push(...v.ranges);- return list;- }, [] as IRange[]);- }- return [];- }),- bufferTime(300), // updating the listener moves to the next queue- map((values) =>- values.reduce((pre, cur) => {- pre.push(...cur);- return pre;- }, [])- ),- filter((values) => !!values.length)- )- .subscribe((ranges) => {- ranges.forEach((range) => {- Range.foreach(range, (row, col) => {- const key = `${row}_${col}`;- const disposable = disposableMap.get(key);- disposableMap.delete(key);- disposable && disposable.dispose();- const value = this._numfmtService.getValue(unitId, subUnitId, row, col);- if (value) {- const targetRange = {- startRow: row,- startColumn: col,- endRow: row,- endColumn: col,- };- const disposable = this._refRangeService.registerRefRange(- targetRange,- (commandInfo) => register(commandInfo, row, col)- );- disposableMap.set(key, disposable);- disposableCollection.add(disposable);- }- });- });- })- )- );- })- )- );- }-}diff --git a/packages/sheets-numfmt/src/controllers/numfmt.sheet.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.sheet.controller.tsdeleted file mode 100644index 181190143b..0000000000--- a/packages/sheets-numfmt/src/controllers/numfmt.sheet.controller.ts+++ /dev/null@@ -1,77 +0,0 @@-/**- * Copyright 2023-present DreamNum Inc.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { IRange, Workbook } from '@univerjs/core';-import { Disposable, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';-import type { IRemoveNumfmtMutationParams, IRemoveSheetCommandParams } from '@univerjs/sheets';-import {- factoryRemoveNumfmtUndoMutation,- INumfmtService,- rangeMerge,- RemoveNumfmtMutation,- RemoveSheetCommand,- SheetInterceptorService,-} from '@univerjs/sheets';-import { Inject, Injector } from '@wendellhu/redi';--@OnLifecycle(LifecycleStages.Rendered, NumfmtSheetController)-export class NumfmtSheetController extends Disposable {- constructor(- @Inject(INumfmtService) private _numfmtService: INumfmtService,- @Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,- @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,- @Inject(Injector) private _injector: Injector- ) {- super();- this._initSheetChange();- }-- private _initSheetChange() {- this.disposeWithMe(- this._sheetInterceptorService.interceptCommand({- getMutations: (commandInfo) => {- if (commandInfo.id === RemoveSheetCommand.id) {- const params = commandInfo.params as IRemoveSheetCommandParams;- const unitId = params.unitId || getUnitId(this._univerInstanceService);- const subUnitId = params.subUnitId || getSubUnitID(this._univerInstanceService);- const model = this._numfmtService.getModel(unitId, subUnitId);- if (!model) {- return { redos: [], undos: [] };- }- const ranges: IRange[] = [];- model.forValue((row, col) => {- ranges.push({ startColumn: col, endColumn: col, startRow: row, endRow: row });- });- const redoParams: IRemoveNumfmtMutationParams = {- unitId,- subUnitId,- ranges: rangeMerge(ranges),- };- const undoParams = factoryRemoveNumfmtUndoMutation(this._injector, redoParams);- return {- redos: [{ id: RemoveNumfmtMutation.id, params: redoParams }],- undos: undoParams,- };- }- return { redos: [], undos: [] };- },- })- );- }-}--const getUnitId = (u: IUniverInstanceService) => u.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getUnitId();-const getSubUnitID = (u: IUniverInstanceService) => u.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!.getActiveSheet().getSheetId();diff --git a/packages/sheets-numfmt/src/menu/menu.ts b/packages/sheets-numfmt/src/menu/menu.tsindex a5ec95c948..2a6968027d 100644--- a/packages/sheets-numfmt/src/menu/menu.ts+++ b/packages/sheets-numfmt/src/menu/menu.ts@@ -28,7 +28,6 @@ import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from 'import type { IAccessor } from '@wendellhu/redi';import { merge, Observable } from 'rxjs';-import { FormulaDataModel } from '@univerjs/engine-formula';import { deriveStateFromActiveSheet$ } from '@univerjs/sheets-ui';import { MENU_OPTIONS } from '../base/const/MENU-OPTIONS';import { AddDecimalCommand } from '../commands/commands/add-decimal.command';@@ -115,7 +114,6 @@ export const FactoryOtherMenuItem = (componentManager: ComponentManager) => {return (_accessor: IAccessor) => {const numfmtService = _accessor.get(INumfmtService);- const formulaDataModel = _accessor.get(FormulaDataModel);const univerInstanceService = _accessor.get(IUniverInstanceService);const commandService = _accessor.get(ICommandService);const localeService = _accessor.get(LocaleService);@@ -141,9 +139,8 @@ export const FactoryOtherMenuItem = (componentManager: ComponentManager) => {const col = range.startColumn;const numfmtValue = numfmtService.getValue(workbook.getUnitId(), worksheet.getSheetId(), row, col);- const numfmtValueByFormula = formulaDataModel.getNumfmtValue(workbook.getUnitId(), worksheet.getSheetId(), row, col);- const pattern = numfmtValue?.pattern || numfmtValueByFormula;+ const pattern = numfmtValue?.pattern;let value: string = localeService.t('sheet.numfmt.general');if (pattern) {diff --git a/packages/sheets-numfmt/src/numfmt-plugin.ts b/packages/sheets-numfmt/src/numfmt-plugin.tsindex 111878669a..9121a66739 100644--- a/packages/sheets-numfmt/src/numfmt-plugin.ts+++ b/packages/sheets-numfmt/src/numfmt-plugin.ts@@ -18,15 +18,11 @@ import { Plugin, UniverInstanceType } from '@univerjs/core';import { Inject, Injector } from '@wendellhu/redi';import { SHEET_NUMFMT_PLUGIN } from './base/const/PLUGIN_NAME';-import { NumfmtAutoFillController } from './controllers/numfmt.auto-fill.controller';import { NumfmtCellContent } from './controllers/numfmt.cell-content.controller';import { NumfmtController } from './controllers/numfmt.controller';-import { NumfmtCopyPasteController } from './controllers/numfmt.copy-paste.controller';import { NumfmtEditorController } from './controllers/numfmt.editor.controller';import { NumfmtI18nController } from './controllers/numfmt.i18n.controller';import { NumfmtMenuController } from './controllers/numfmt.menu.controller';-import { NumfmtRefRangeController } from './controllers/numfmt.ref-range.controller';-import { NumfmtSheetController } from './controllers/numfmt.sheet.controller';import { INumfmtController } from './controllers/type';import { UserHabitController } from './controllers/user-habit.controller';@@ -45,10 +41,6 @@ export class UniverSheetsNumfmtPlugin extends Plugin {this._injector.add([INumfmtController, { useClass: NumfmtController, lazy: false }]);this._injector.add([NumfmtEditorController]);this._injector.add([UserHabitController]);- this._injector.add([NumfmtRefRangeController]);- this._injector.add([NumfmtSheetController]);- this._injector.add([NumfmtCopyPasteController]);- this._injector.add([NumfmtAutoFillController]);this._injector.add([NumfmtCellContent]);this._injector.add([NumfmtI18nController]);this._injector.add([NumfmtMenuController]);diff --git a/packages/sheets-numfmt/src/utils/pattern.ts b/packages/sheets-numfmt/src/utils/pattern.tsindex 1d2e2f3239..5b2a734ad1 100644--- a/packages/sheets-numfmt/src/utils/pattern.ts+++ b/packages/sheets-numfmt/src/utils/pattern.ts@@ -15,8 +15,8 @@*/import numfmt from '@univerjs/engine-numfmt';-import type { FormatType } from '@univerjs/sheets';import { LocaleType } from '@univerjs/core';+import type { FormatType } from '@univerjs/sheets';export const getPatternType = (pattern: string): FormatType => numfmt.getInfo(pattern).type || 'unknown';export const getPatternPreview = (pattern: string, value: number, _locale?: LocaleType) => {diff --git a/packages/sheets/package.json b/packages/sheets/package.jsonindex 8b39c92eda..ff433b9c6a 100644--- a/packages/sheets/package.json+++ b/packages/sheets/package.json@@ -75,6 +75,7 @@"devDependencies": {"@univerjs/core": "workspace:*","@univerjs/engine-formula": "workspace:*",+ "@univerjs/engine-numfmt": "workspace:*","@univerjs/engine-render": "workspace:*","@univerjs/shared": "workspace:*","@wendellhu/redi": "^0.13.1",diff --git a/packages/sheets/src/basics/__tests__/numfmt-kit.spec.ts b/packages/sheets/src/basics/__tests__/numfmt-kit.spec.tsnew file mode 100644index 0000000000..2edc15771d--- /dev/null+++ b/packages/sheets/src/basics/__tests__/numfmt-kit.spec.ts@@ -0,0 +1,164 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';+import { compareNumfmtPriority } from '../numfmt-kit';++const numfmtMap = {+ currency: '"¥"#,##0.00_);[Red]("¥"#,##0.00)',+ date: 'yyyy-mm-dd;@',+ datetime: 'yyyy-m-d am/pm h:mm',+ error: '#,##0',+ fraction: '# ?/?',+ grouped: '#,##0',+ number: '0',+ percent: '0%',+ scientific: '0.00E+00',+ text: '@@@',+ time: 'am/pm h":"mm":"ss',+ unknown: '#,##0',+ accounting: '_("¤"* #,##0.000_)',+};++describe('Test numfmt kit', () => {+ it('Function compareNumfmtPriority', () => {+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.currency)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.date)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.datetime)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.error)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.fraction)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.grouped)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.number)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.percent)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.scientific)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.text)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.time)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.unknown)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.currency, numfmtMap.accounting)).toBe(numfmtMap.currency);++ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.currency)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.date)).toBe(numfmtMap.date);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.datetime)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.error)).toBe(numfmtMap.error);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.fraction)).toBe(numfmtMap.fraction);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.grouped)).toBe(numfmtMap.grouped);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.number)).toBe(numfmtMap.date);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.percent)).toBe(numfmtMap.percent);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.scientific)).toBe(numfmtMap.scientific);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.text)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.time)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.unknown)).toBe(numfmtMap.unknown);+ expect(compareNumfmtPriority(numfmtMap.date, numfmtMap.accounting)).toBe(numfmtMap.accounting);++ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.currency)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.date)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.datetime)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.error)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.fraction)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.grouped)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.number)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.percent)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.scientific)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.text)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.time)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.unknown)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.datetime, numfmtMap.accounting)).toBe(numfmtMap.datetime);++ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.currency)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.date)).toBe(numfmtMap.date);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.datetime)).toBe(numfmtMap.error);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.error)).toBe(numfmtMap.error);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.fraction)).toBe(numfmtMap.fraction);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.grouped)).toBe(numfmtMap.error);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.number)).toBe(numfmtMap.error);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.percent)).toBe(numfmtMap.percent);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.scientific)).toBe(numfmtMap.scientific);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.text)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.time)).toBe(numfmtMap.error);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.unknown)).toBe(numfmtMap.error);+ expect(compareNumfmtPriority(numfmtMap.error, numfmtMap.accounting)).toBe(numfmtMap.accounting);++ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.currency)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.date)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.datetime)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.error)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.fraction)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.grouped)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.number)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.percent)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.scientific)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.text)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.time)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.unknown)).toBe(numfmtMap.number);+ expect(compareNumfmtPriority(numfmtMap.number, numfmtMap.accounting)).toBe(numfmtMap.number);++ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.currency)).toBe(numfmtMap.currency);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.date)).toBe(numfmtMap.date);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.datetime)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.error)).toBe(numfmtMap.error);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.fraction)).toBe(numfmtMap.fraction);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.grouped)).toBe(numfmtMap.grouped);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.number)).toBe(numfmtMap.percent);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.percent)).toBe(numfmtMap.percent);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.scientific)).toBe(numfmtMap.scientific);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.text)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.time)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.unknown)).toBe(numfmtMap.unknown);+ expect(compareNumfmtPriority(numfmtMap.percent, numfmtMap.accounting)).toBe(numfmtMap.accounting);++ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.currency)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.date)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.datetime)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.error)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.fraction)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.grouped)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.number)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.percent)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.scientific)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.text)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.time)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.unknown)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.text, numfmtMap.accounting)).toBe(numfmtMap.text);++ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.currency)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.date)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.datetime)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.error)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.fraction)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.grouped)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.number)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.percent)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.scientific)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.text)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.time)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.unknown)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.time, numfmtMap.accounting)).toBe(numfmtMap.time);++ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.currency)).toBe(numfmtMap.accounting);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.date)).toBe(numfmtMap.date);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.datetime)).toBe(numfmtMap.datetime);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.error)).toBe(numfmtMap.error);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.fraction)).toBe(numfmtMap.fraction);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.grouped)).toBe(numfmtMap.grouped);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.number)).toBe(numfmtMap.accounting);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.percent)).toBe(numfmtMap.percent);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.scientific)).toBe(numfmtMap.scientific);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.text)).toBe(numfmtMap.text);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.time)).toBe(numfmtMap.time);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.unknown)).toBe(numfmtMap.unknown);+ expect(compareNumfmtPriority(numfmtMap.accounting, numfmtMap.accounting)).toBe(numfmtMap.accounting);+ });+});diff --git a/packages/sheets/src/basics/numfmt-kit.ts b/packages/sheets/src/basics/numfmt-kit.tsnew file mode 100644index 0000000000..c87209c9f4--- /dev/null+++ b/packages/sheets/src/basics/numfmt-kit.ts@@ -0,0 +1,197 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ICellData, Nullable, Styles } from '@univerjs/core';+import numfmt from '@univerjs/engine-numfmt';++const currencySymbols = [+ '$',+ '£',+ '¥',+ '¤',+ '֏',+ '؋',+ '৳',+ '฿',+ '៛',+ '₡',+ '₦',+ '₩',+ '₪',+ '₫',+ '€',+ '₭',+ '₮',+ '₱',+ '₲',+ '₴',+ '₸',+ '₹',+ '₺',+ '₼',+ '₽',+ '₾',+ '₿',+];++enum NumberFormatType {+ General,+ Number,+ Currency,+ Accounting,+ Date,+ Time,+ Percentage,+ Fraction,+ Scientific,+ Text,+ Special,+ Custom,+}++// except error/grouped+const NumberFormatTypeMap = {+ currency: NumberFormatType.Currency,+ date: NumberFormatType.Date,+ datetime: NumberFormatType.Time,+ error: NumberFormatType.Custom,+ fraction: NumberFormatType.Fraction,+ general: NumberFormatType.General,+ grouped: NumberFormatType.Custom,+ number: NumberFormatType.Number,+ percent: NumberFormatType.Percentage,+ scientific: NumberFormatType.Scientific,+ text: NumberFormatType.Text,+ time: NumberFormatType.Time,+ unknown: NumberFormatType.Custom,+};+/**+ * Handling number formats in styles+ *+ * @param oldCell+ * @param cell+ */+export function handleNumfmtInCell(oldCell: Nullable<ICellData>, cell: Nullable<ICellData>, styles: Styles | undefined) {+ if (oldCell == null || cell == null) {+ return cell;+ }++ const oldCellStyle = styles?.getStyleByCell(oldCell) || oldCell.s;+ const cellStyle = styles?.getStyleByCell(cell) || cell.s;++ if (oldCellStyle == null || cellStyle == null || typeof oldCellStyle !== 'object' || typeof cellStyle !== 'object') {+ return cell;+ }++ const oldPattern = oldCellStyle?.n?.pattern;+ const pattern = cellStyle?.n?.pattern;++ if (oldPattern == null || pattern == null) {+ return cell;+ }++ const newPattern = compareNumfmtPriority(oldPattern, pattern);++ cellStyle!.n!.pattern = newPattern;++ return cell;+}++/**+ * Process the priority of the newly set number format and the original format.+ *+ * Here is the priority of the number format in Excel:+ * ┌─────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐+ * │ │ new format │+ * ├─────────────────┼────────────┬────────────┬────────────┬────────────┬──────────┬──────────┬────────────┬──────────┬────────────┬──────────┬────────────┬───────────┤+ * │ Original format │ General │ Number │ Currency │ Accounting │ Date │ Time │ Percentage │ Fraction │ Scientific │ Text │ Special │ Custom │+ * ├─────────────────┼────────────┼────────────┼────────────┼────────────┼──────────┼──────────┼────────────┼──────────┼────────────┼──────────┼────────────┼───────────┤+ * │ General │ General │ Number │ Currency │ Accounting │ Date │ Time │ Percentage │ Fraction │ Scientific │ Text │ Special │ Custom │+ * │ Number │ Number │ Number │ Number │ Number │ Number │ Number │ Number │ Number │ Number │ Number │ Number │ Number │+ * │ Currency │ Currency │ Currency │ Currency │ Currency │ Currency │ Currency │ Currency │ Currency │ Currency │ Currency │ Currency │ Currency │+ * │ Accounting │ Accounting │ Accounting │ Accounting │ Accounting │ Date │ Time │ Percentage │ Fraction │ Scientific │ Text │ Accounting │ Custom │+ * │ Date │ Date │ Date │ Currency │ Accounting │ Date │ Time │ Percentage │ Fraction │ Scientific │ Text │ Date │ Custom │+ * │ Time │ Time │ Time │ Time │ Time │ Time │ Time │ Time │ Time │ Time │ Time │ Time │ Time │+ * │ Percentage │ Percentage │ Percentage │ Currency │ Accounting │ Date │ Time │ Percentage │ Fraction │ Scientific │ Text │ Percentage │ Custom │+ * │ Fraction │ Fraction │ Fraction │ Currency │ Accounting │ Date │ Time │ Percentage │ Fraction │ Scientific │ Text │ Fraction │ Custom │+ * │ Scientific │ Scientific │ Scientific │ Currency │ Accounting │ Date │ Time │ Percentage │ Fraction │ Scientific │ Text │ Scientific │ Custom │+ * │ Text │ Text │ Text │ Text │ Text │ Text │ Text │ Text │ Text │ Text │ Text │ Text │ Text │+ * │ Special │ Special │ Special │ Special │ Special │ Special │ Special │ Special │ Special │ Special │ Special │ Special │ Special │+ * │ Custom │ Custom │ Custom │ Currency │ Accounting │ Date │ Custom │ Percentage │ Fraction │ Scientific │ Text │ Custom │ Custom │+ * └─────────────────┴────────────┴────────────┴────────────┴────────────┴──────────┴──────────┴────────────┴──────────┴────────────┴──────────┴────────────┴───────────┘+ *+ * The number formats supported by Univer are different from Excel, so it only processes the parts that are the same as Excel. For different parts, we consider the newly set number format to have a higher priority.+ *+ * In the future, if Univer completely matches Excel, we will implement Excel’s priority rules.+ *+ * @param oldPattern+ * @param pattern+ * @returns+ */+export function compareNumfmtPriority(oldPattern: string, pattern: string) {+ const oldPatternType = getNumberFormatType(oldPattern);+ const patternType = getNumberFormatType(pattern);++ if (oldPatternType === NumberFormatType.General) {+ return pattern;+ }++ if ([NumberFormatType.Number, NumberFormatType.Currency, NumberFormatType.Time, NumberFormatType.Text, NumberFormatType.Special].includes(oldPatternType)) {+ return oldPattern;+ }++ if (oldPatternType === NumberFormatType.Accounting) {+ if ([NumberFormatType.Date, NumberFormatType.Time, NumberFormatType.Percentage, NumberFormatType.Fraction, NumberFormatType.Scientific, NumberFormatType.Text, NumberFormatType.Custom].includes(patternType)) {+ return pattern;+ }+ return oldPattern;+ }++ if ([NumberFormatType.Date, NumberFormatType.Percentage, NumberFormatType.Fraction, NumberFormatType.Scientific].includes(oldPatternType)) {+ if ([NumberFormatType.Currency, NumberFormatType.Accounting, NumberFormatType.Date, NumberFormatType.Time, NumberFormatType.Percentage, NumberFormatType.Fraction, NumberFormatType.Scientific, NumberFormatType.Text, NumberFormatType.Custom].includes(patternType)) {+ return pattern;+ }+ return oldPattern;+ }++ if (oldPatternType === NumberFormatType.Custom) {+ if ([NumberFormatType.Currency, NumberFormatType.Accounting, NumberFormatType.Date, NumberFormatType.Percentage, NumberFormatType.Fraction, NumberFormatType.Scientific, NumberFormatType.Text].includes(patternType)) {+ return pattern;+ }+ return oldPattern;+ }++ return oldPattern;+}++/**+ * Get the type of the number format+ *+ * @param pattern+ * @returns+ */+function getNumberFormatType(pattern: string): NumberFormatType {+ if (isAccounting(pattern)) {+ return NumberFormatType.Accounting;+ }++ const type = numfmt.getInfo(pattern).type || 'unknown';+ return NumberFormatTypeMap[type];+}++function isAccounting(pattern: string) {+ return !!currencySymbols.find((code) => pattern.includes(code)) && pattern.startsWith('_(');+};diff --git a/packages/sheets/src/commands/mutations/numfmt-mutation.ts b/packages/sheets/src/commands/mutations/numfmt-mutation.tsindex b711779cef..17729c2579 100644--- a/packages/sheets/src/commands/mutations/numfmt-mutation.ts+++ b/packages/sheets/src/commands/mutations/numfmt-mutation.ts@@ -20,7 +20,6 @@ import type { IAccessor } from '@wendellhu/redi';import { rangeMerge } from '../../basics/rangeMerge';import { createUniqueKey, groupByKey } from '../../basics/utils';-import type { FormatType } from '../../services/numfmt/type';import { INumfmtService } from '../../services/numfmt/type';export const factorySetNumfmtUndoMutation = (accessor: IAccessor, option: ISetNumfmtMutationParams) => {@@ -28,16 +27,14 @@ export const factorySetNumfmtUndoMutation = (accessor: IAccessor, option: ISetNuconst { values, unitId, subUnitId } = option;const cells: ISetCellsNumfmt = [];const removeCells: IRange[] = [];- const model = numfmtService.getModel(unitId, subUnitId) || undefined;Object.keys(values).forEach((id) => {const value = values[id];value.ranges.forEach((range) => {Range.foreach(range, (row, col) => {- const oldNumfmt = numfmtService.getValue(unitId, subUnitId, row, col, model);+ const oldNumfmt = numfmtService.getValue(unitId, subUnitId, row, col);if (oldNumfmt) {cells.push({pattern: oldNumfmt.pattern,- type: oldNumfmt.type,row,col,});@@ -81,7 +78,6 @@ export interface ISetNumfmtMutationParams {refMap: {[id: string]: {pattern: string;- type: FormatType;};};unitId: string;@@ -111,7 +107,7 @@ export const SetNumfmtMutation: ICommand<ISetNumfmtMutationParams> = {}return result;},- [] as Array<{ pattern: string; type: FormatType; ranges: IRange[] }>+ [] as Array<{ pattern: string; ranges: IRange[] }>);numfmtService.setValues(unitId, sheetId, setValues);return true;@@ -140,14 +136,12 @@ export const factoryRemoveNumfmtUndoMutation = (accessor: IAccessor, option: IReconst numfmtService = accessor.get(INumfmtService);const { ranges, unitId, subUnitId } = option;const cells: ISetCellsNumfmt = [];- const model = numfmtService.getModel(unitId, subUnitId) || undefined;ranges.forEach((range) => {Range.foreach(range, (row, col) => {- const oldNumfmt = numfmtService.getValue(unitId, subUnitId, row, col, model);+ const oldNumfmt = numfmtService.getValue(unitId, subUnitId, row, col);if (oldNumfmt) {cells.push({pattern: oldNumfmt.pattern,- type: oldNumfmt.type,row,col,});@@ -164,7 +158,7 @@ export const factoryRemoveNumfmtUndoMutation = (accessor: IAccessor, option: IRe});return [{ id: SetNumfmtMutation.id, params }];};-export type ISetCellsNumfmt = Array<{ pattern: string; type: FormatType; row: number; col: number }>;+export type ISetCellsNumfmt = Array<{ pattern: string; row: number; col: number }>;export const transformCellsToRange = (unitId: string,subUnitId: string,@@ -176,11 +170,9 @@ export const transformCellsToRange = (const getKey = createUniqueKey();Object.keys(group).forEach((pattern) => {const groupItem = group[pattern];- const firstOne = groupItem[0];const key = getKey();refMap[key] = {pattern,- type: firstOne.type,};groupItem.forEach((item) => {if (!values[key]) {diff --git a/packages/sheets/src/controllers/calculate-result-apply.controller.ts b/packages/sheets/src/controllers/calculate-result-apply.controller.tsindex 23f4ed0385..3875315501 100644--- a/packages/sheets/src/controllers/calculate-result-apply.controller.ts+++ b/packages/sheets/src/controllers/calculate-result-apply.controller.ts@@ -14,16 +14,21 @@* limitations under the License.*/-import type { ICommandInfo } from '@univerjs/core';-import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';+import type { ICellData, ICommandInfo, IObjectMatrixPrimitiveType, Nullable } from '@univerjs/core';+import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, ObjectMatrix, OnLifecycle } from '@univerjs/core';import type { ISetFormulaCalculationResultMutation } from '@univerjs/engine-formula';import { SetFormulaCalculationResultMutation } from '@univerjs/engine-formula';+import { Inject } from '@wendellhu/redi';import { SetRangeValuesMutation } from '../commands/mutations/set-range-values.mutation';+import { handleNumfmtInCell } from '../basics/numfmt-kit';@OnLifecycle(LifecycleStages.Ready, CalculateResultApplyController)export class CalculateResultApplyController extends Disposable {- constructor(@ICommandService private readonly _commandService: ICommandService) {+ constructor(+ @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,+ @ICommandService private readonly _commandService: ICommandService+ ) {super();this._initialize();@@ -42,7 +47,7 @@ export class CalculateResultApplyController extends Disposable {const params = command.params as ISetFormulaCalculationResultMutation;- const { unitData, unitOtherData } = params;+ const { unitData } = params;const unitIds = Object.keys(unitData);@@ -67,10 +72,12 @@ export class CalculateResultApplyController extends Disposable {return true;}+ const cellValue = this._getMergedCellData(unitId, sheetId, cellData);+const setRangeValuesMutation = {subUnitId: sheetId,unitId,- cellValue: cellData,+ cellValue,};redoMutationsInfo.push({@@ -89,4 +96,28 @@ export class CalculateResultApplyController extends Disposable {}));}++ /**+ * Priority that mainly deals with number format in unitData+ * @param unitId+ * @param sheetId+ * @param cellData+ * @returns+ */+ private _getMergedCellData(unitId: string, sheetId: string, cellData: IObjectMatrixPrimitiveType<Nullable<ICellData>>) {+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const styles = workbook?.getStyles();++ const worksheet = workbook?.getSheetBySheetId(sheetId);+ const oldCellDataMatrix = worksheet?.getCellMatrix();+ const cellDataMatrix = new ObjectMatrix(cellData);++ cellDataMatrix.forValue((row, col, cell) => {+ const oldCell = oldCellDataMatrix?.getValue(row, col);+ const newCell = handleNumfmtInCell(oldCell, cell, styles);+ cellDataMatrix.setValue(row, col, newCell);+ });++ return cellDataMatrix.clone();+ }}diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.tsindex b2d1a2b169..917934ab49 100644--- a/packages/sheets/src/index.ts+++ b/packages/sheets/src/index.ts@@ -258,7 +258,7 @@ export { type ISheetCommandSharedParams } from './commands/utils/interface';export { getAddMergeMutationRangeByType } from './controllers/merge-cell.controller';export { enUS, zhCN } from './locale';export { NumfmtService } from './services/numfmt/numfmt.service';-export type { FormatType, INumfmtItem, INumfmtItemWithCache } from './services/numfmt/type';+export type { INumfmtItem, INumfmtItemWithCache } from './services/numfmt/type';export { INumfmtService } from './services/numfmt/type';export { RefRangeService } from './services/ref-range/ref-range.service';export type { EffectRefRangeParams, IOperator } from './services/ref-range/type';@@ -293,3 +293,4 @@ export { InsertDefinedNameCommand } from './commands/commands/insert-defined-namexport { RemoveDefinedNameCommand } from './commands/commands/remove-defined-name.command';export { SetDefinedNameCommand, type ISetDefinedNameCommandParams } from './commands/commands/set-defined-name.command';export { ScrollToCellOperation } from './commands/operations/scroll-to-cell.operation';+export type { FormatType } from './services/numfmt/type';diff --git a/packages/sheets/src/services/__tests__/numfmt.service.test.ts b/packages/sheets/src/services/__tests__/numfmt.service.test.tsindex d775fe33eb..7dd85b2204 100644--- a/packages/sheets/src/services/__tests__/numfmt.service.test.ts+++ b/packages/sheets/src/services/__tests__/numfmt.service.test.ts@@ -43,31 +43,6 @@ describe('test numfmt service', () => {univer.dispose();});- it('model set', () => {- const univerInstanceService = get(IUniverInstanceService);- const numfmtService = get(INumfmtService);- const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;- const sheet = workbook.getActiveSheet();- const unitId = workbook.getUnitId();- const subUnitId = sheet.getSheetId();- const params: ISetNumfmtMutationParams = {- unitId,- subUnitId,- refMap: {- 1: {- pattern: 'asdws',- type: 'sss' as any,- },- },- values: { 1: { ranges: [cellToRange(1, 1)] } },- };- commandService.executeCommand(SetNumfmtMutation.id, params);- const numfmtValue = numfmtService.getValue(unitId, subUnitId, 1, 1);- expect(numfmtValue).toEqual({ pattern: 'asdws', type: 'sss' });- const model = numfmtService.getModel(unitId, subUnitId);- expect(model?.getValue(1, 1)).toEqual({ i: '1' });- });-it('model delete', () => {const univerInstanceService = get(IUniverInstanceService);const numfmtService = get(INumfmtService);@@ -81,7 +56,6 @@ describe('test numfmt service', () => {refMap: {1: {pattern: 'asdws',- type: 'sss' as any,},},values: { 1: { ranges: [cellToRange(1, 1)] } },@@ -93,42 +67,17 @@ describe('test numfmt service', () => {};commandService.executeCommand(SetNumfmtMutation.id, params);const numfmtValue = numfmtService.getValue(unitId, subUnitId, 1, 1);- expect(numfmtValue).toEqual({ pattern: 'asdws', type: 'sss' });+ expect(numfmtValue).toEqual({ pattern: 'asdws' });commandService.executeCommand(RemoveNumfmtMutation.id, deleteParams);const numfmtValueDelete = numfmtService.getValue(unitId, subUnitId, 1, 1);expect(numfmtValueDelete).toEqual(null);});- it('ref model set', () => {- const univerInstanceService = get(IUniverInstanceService);- const numfmtService = get(INumfmtService);- const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;- const sheet = workbook.getActiveSheet();- const unitId = workbook.getUnitId();- const subUnitId = sheet.getSheetId();- const params: ISetNumfmtMutationParams = {- unitId,- subUnitId,- refMap: {- 1: {- pattern: 'asdws',- type: 'sss' as any,- },- },- values: { 1: { ranges: [cellToRange(1, 1)] } },- };- commandService.executeCommand(SetNumfmtMutation.id, params);- const refModel = numfmtService.getRefModel(unitId);- expect(refModel?.getKeyMap('i')).toEqual(['1']);- expect(refModel?.getKeyMap('pattern')).toEqual(['asdws']);- expect(refModel?.getValue('asdws')?.count).toEqual(1);- expect(refModel?.getValue('1')?.count).toEqual(1);- });-- it('model delete', () => {+ it('model set', () => {const univerInstanceService = get(IUniverInstanceService);const numfmtService = get(INumfmtService);const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;+ const styles = workbook.getStyles();const sheet = workbook.getActiveSheet();const unitId = workbook.getUnitId();const subUnitId = sheet.getSheetId();@@ -138,60 +87,14 @@ describe('test numfmt service', () => {refMap: {1: {pattern: 'asdws',- type: 'sss' as any,},},values: { 1: { ranges: [cellToRange(1, 1)] } },};- const deleteParams: IRemoveNumfmtMutationParams = {- unitId,- subUnitId,- ranges: [cellToRange(1, 1)],- };commandService.executeCommand(SetNumfmtMutation.id, params);- commandService.executeCommand(RemoveNumfmtMutation.id, deleteParams);- const refModel = numfmtService.getRefModel(unitId);- expect(refModel?.getValue('asdws')?.count).toEqual(0);- expect(refModel?.getValue('1')?.count).toEqual(0);- });-- it('model delete', () => {- const univerInstanceService = get(IUniverInstanceService);- const numfmtService = get(INumfmtService);- const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.SHEET)!;- const unitId = workbook.getUnitId();- const sheets = workbook.getSheets();- const pattern = 'asdws';- const params1: ISetNumfmtMutationParams = {- unitId,- subUnitId: sheets[0].getSheetId(),- refMap: {- 1: {- pattern,- type: 'sss' as any,- },- },- values: { 1: { ranges: [cellToRange(1, 1)] } },- };- commandService.executeCommand(SetNumfmtMutation.id, params1);- const params2: ISetNumfmtMutationParams = {- unitId,- subUnitId: sheets[1].getSheetId(),- refMap: {- 1: {- pattern,- type: 'sss' as any,- },- },- values: { 1: { ranges: [cellToRange(1, 1)] } },- };- commandService.executeCommand(SetNumfmtMutation.id, params2);- const refModel = numfmtService.getRefModel(unitId);- const model1 = numfmtService.getModel(unitId, sheets[0].getSheetId());- const model2 = numfmtService.getModel(unitId, sheets[1].getSheetId());- expect(refModel?.getValue(pattern)?.count).toBe(2);- expect(model1?.getValue(1, 1)?.i).toBe('1');- expect(model2?.getValue(1, 1)?.i).toBe('1');- expect(refModel?.getValue(model2?.getValue(1, 1)?.i!)?.pattern).toBe(pattern);+ const numfmt = numfmtService.getValue(unitId, subUnitId, 1, 1);+ expect(numfmt?.pattern).toEqual('asdws');+ const numfmtId = sheet.getCellRaw(1, 1)?.s;+ expect(styles.get(numfmtId)?.n).toEqual({ pattern: 'asdws' });});});diff --git a/packages/sheets/src/services/numfmt/numfmt.service.ts b/packages/sheets/src/services/numfmt/numfmt.service.tsindex cb50ea9551..276180909e 100644--- a/packages/sheets/src/services/numfmt/numfmt.service.ts+++ b/packages/sheets/src/services/numfmt/numfmt.service.ts@@ -14,40 +14,20 @@* limitations under the License.*/-import type { IObjectMatrixPrimitiveType, IRange, Nullable } from '@univerjs/core';+import type { IRange } from '@univerjs/core';import {Disposable,ICommandService,ILogService,IResourceManagerService,IUniverInstanceService,- ObjectMatrix,Range,- RefAlias,- toDisposable,} from '@univerjs/core';import { Inject } from '@wendellhu/redi';-import { Subject } from 'rxjs';-import { UniverType } from '@univerjs/protocol';-import type { FormatType, INumfmtItem, INumfmtService, IRefItem, ISnapshot } from './type';--const SHEET_NUMFMT_PLUGIN = 'SHEET_NUMFMT_PLUGIN';-const millisecondsPerDay = 24 * 60 * 60 * 1000;+import type { INumfmtService } from './type';export class NumfmtService extends Disposable implements INumfmtService {- /**- * Map<unitID ,<sheetId ,ObjectMatrix>>- * @type {Map<string, Map<string, ObjectMatrix<INumfmtItemWithCache>>>}- * @memberof NumfmtService- */- private _numfmtModel: Map<string, Map<string, ObjectMatrix<INumfmtItem>>> = new Map();-- private _refAliasModel: Map<string, RefAlias<IRefItem, 'pattern' | 'i'>> = new Map();-- private _modelReplace$ = new Subject<string>();- modelReplace$ = this._modelReplace$.asObservable();-constructor(@Inject(ICommandService) private _commandService: ICommandService,@Inject(IResourceManagerService) private _resourceManagerService: IResourceManagerService,@@ -55,148 +35,51 @@ export class NumfmtService extends Disposable implements INumfmtService {@Inject(ILogService) private _logService: ILogService) {super();-- this._initModel();- this.disposeWithMe(- toDisposable(() => {- this._numfmtModel.clear();- this._refAliasModel.clear();- })- );- }-- private _initModel() {- this.disposeWithMe(- this._resourceManagerService.registerPluginResource<ISnapshot>({- pluginName: SHEET_NUMFMT_PLUGIN,- businesses: [UniverType.UNIVER_SHEET],- toJson: (unitID) => this._toJson(unitID),- parseJson: (json) => this._parseJson(json),- onUnLoad: (unitID) => {- this._numfmtModel.delete(unitID);- this._refAliasModel.delete(unitID);- },- onLoad: (unitID, value) => {- const { model, refModel } = value;- if (model) {- const parseModel = Object.keys(model).reduce((result, sheetId) => {- result.set(sheetId, new ObjectMatrix<INumfmtItem>(model[sheetId]));- return result;- }, new Map<string, ObjectMatrix<INumfmtItem>>());- this._numfmtModel.set(unitID, parseModel);- }- if (refModel) {- this._refAliasModel.set(- unitID,- new RefAlias<IRefItem, 'pattern' | 'i'>(refModel, ['pattern', 'i'])- );- }- this._modelReplace$.next(unitID);- },- })- );- }-- private _toJson(unitID: string) {- const workbookModel = this._numfmtModel.get(unitID);- const workbookRefModel = this._refAliasModel.get(unitID);- if (!workbookModel || !workbookRefModel) {- return '';- }- const model = [...workbookModel.keys()].reduce(- (result, key) => {- const object = workbookModel.get(key)!;- result[key] = object.toJSON();- return result;- },- {} as Record<string, IObjectMatrixPrimitiveType<INumfmtItem>>- );- // Filter the count equal 0 when snapshot save.- // It is typically cleaned up once every 100 versions.-- const refModel = workbookRefModel.getValues().filter((item) => item.count > 0);- const obj: ISnapshot = { model, refModel };- return JSON.stringify(obj);- }-- private _parseJson(json: string): ISnapshot {- try {- const obj = JSON.parse(json);- return obj;- } catch (err) {- return { model: {}, refModel: [] };- }- }-- private _setValue(unitId: string, subUnitId: string, row: number, col: number, value: Nullable<INumfmtItem>) {- let model = this.getModel(unitId, subUnitId);- if (!model) {- const worksheetMap = this._numfmtModel.get(unitId) || new Map<string, ObjectMatrix<INumfmtItem>>();- const worksheetModel = worksheetMap.get(subUnitId) || new ObjectMatrix<INumfmtItem>();- worksheetMap.set(subUnitId, worksheetModel);- this._numfmtModel.set(unitId, worksheetMap);- model = worksheetModel;- }- if (value) {- model.setValue(row, col, value);- } else {- model.realDeleteValue(row, col);- const size = model.getSizeOf();- if (!size) {- const workbookModel = this._numfmtModel.get(unitId);- workbookModel?.delete(subUnitId);- }- }}- private _getUniqueRefId(unitID: string) {- const refModel = this._refAliasModel.get(unitID);- if (!refModel) {- return '0';+ getValue(unitId: string, subUnitId: string, row: number, col: number) {+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ if (!workbook) {+ return;}- const keyList = refModel.getKeyMap('i') as string[];- const maxId = Math.max(...keyList.map((item) => Number(item || 0)), 0);- return `${maxId + 1}`;- }-- getValue(unitId: string, subUnitId: string, row: number, col: number, model?: ObjectMatrix<INumfmtItem>) {- const _model: Nullable<ObjectMatrix<INumfmtItem>> = model || this.getModel(unitId, subUnitId);- if (!_model) {- return null;+ const worksheet = workbook?.getSheetBySheetId(subUnitId);+ if (!worksheet) {+ return;}- const refMode = this._refAliasModel.get(unitId);- const value = _model.getValue(row, col);- if (value && refMode) {- const refValue = refMode.getValue(value?.i, ['i']);- if (!refValue) {- this._logService.error('[Numfmt Service]:', 'RefAliasModel is not match model');- return null;+ const styles = workbook.getStyles();+ const cell = worksheet.getCellRaw(row, col);+ if (cell?.s) {+ const style = styles.get(cell.s);+ if (style?.n) {+ return style.n;}- return {- pattern: refValue.pattern,- type: refValue.type,- };}return null;}deleteValues(unitId: string, subUnitId: string, values: IRange[]) {- let refModel = this._refAliasModel.get(unitId)!;- const model = this.getModel(unitId, subUnitId);- if (!refModel) {- refModel = new RefAlias<IRefItem, 'i' | 'pattern'>([], ['pattern', 'i']);- this._refAliasModel.set(unitId, refModel);+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ if (!workbook) {+ return;}+ const worksheet = workbook?.getSheetBySheetId(subUnitId);+ if (!worksheet) {+ return;+ }+ const styles = workbook.getStyles();+values.forEach((range) => {Range.foreach(range, (row, col) => {- const oldValue = this.getValue(unitId, subUnitId, row, col, model);- if (oldValue && oldValue.pattern) {- const oldRefPattern = refModel.getValue(oldValue.pattern, ['pattern']);- if (oldRefPattern) {- oldRefPattern.count--;- }+ const cell = worksheet.getCellRaw(row, col);+ if (!cell) {+ return;}- this._setValue(unitId, subUnitId, row, col, null);+ const oldStyleId = cell?.s;+ const oldStyle = (oldStyleId && styles.get(oldStyleId)) || {};+ const newStyle = { ...oldStyle };+ delete newStyle.n;+ const newStyleId = styles.setValue(newStyle);+ cell.s = newStyleId;});});}@@ -204,60 +87,35 @@ export class NumfmtService extends Disposable implements INumfmtService {setValues(unitId: string,subUnitId: string,- values: Array<{ ranges: IRange[]; pattern: string; type: FormatType }>+ values: Array<{ ranges: IRange[]; pattern: string }>) {- const model = this.getModel(unitId, subUnitId);- let refModel = this._refAliasModel.get(unitId)!;- if (!refModel) {- refModel = new RefAlias<IRefItem, 'i' | 'pattern'>([], ['pattern', 'i']);- this._refAliasModel.set(unitId, refModel);+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ if (!workbook) {+ return;}- values.forEach((value) => {- let refPattern = refModel.getValue(value.pattern, ['pattern']);- if (!refPattern) {- refPattern = {- count: 0,- i: this._getUniqueRefId(unitId),- pattern: value.pattern,- type: values[0].type,- };- refModel.addValue(refPattern);- }+ const worksheet = workbook?.getSheetBySheetId(subUnitId);+ if (!worksheet) {+ return;+ }+ const styles = workbook.getStyles();+ const matrix = worksheet.getCellMatrix();+ values.forEach((value) => {value.ranges.forEach((range) => {Range.foreach(range, (row, col) => {- if (model) {- const oldValue = this.getValue(unitId, subUnitId, row, col, model);- if (oldValue && oldValue.pattern) {- const oldRefPattern = refModel.getValue(oldValue.pattern, ['pattern']);- if (oldRefPattern) {- oldRefPattern.count--;- }- }+ const cell = worksheet.getCellRaw(row, col);+ if (!cell) {+ const style = { n: { pattern: value.pattern } };+ const styleId = styles.setValue(style);+ styleId && matrix.setValue(row, col, { s: styleId });+ } else {+ const oldStyle = (cell.s && styles.get(cell.s)) || {};+ const newStyle = { ...oldStyle, n: { pattern: value.pattern } };+ const styleId = styles.setValue(newStyle);+ cell.s = styleId;}- this._setValue(unitId, subUnitId, row, col, {- i: refPattern!.i,- });- refPattern!.count++;});});});}-- getModel(unitId: string, subUnitId: string) {- const workbookModel = this._numfmtModel.get(unitId);- const sheetModel = workbookModel?.get(subUnitId);- return sheetModel;- }-- getRefModel(unitId: string) {- const refModel = this._refAliasModel.get(unitId);- return refModel;- }-- serialTimeToTimestamp(serialValue: number, is1900 = true) {- const excelBaseDate = new Date('1900-01-01').getTime();- const timestamp = (serialValue - (is1900 ? 25569 : 24107)) * millisecondsPerDay + excelBaseDate;- return timestamp;- }}diff --git a/packages/sheets/src/services/numfmt/type.ts b/packages/sheets/src/services/numfmt/type.tsindex 7e0c201cb2..2f4687b1f6 100644--- a/packages/sheets/src/services/numfmt/type.ts+++ b/packages/sheets/src/services/numfmt/type.ts@@ -14,10 +14,9 @@* limitations under the License.*/-import type { ICellData, IObjectMatrixPrimitiveType, IRange, Nullable, ObjectMatrix, RefAlias } from '@univerjs/core';+import type { ICellData, IRange, Nullable, ObjectMatrix } from '@univerjs/core';import { LifecycleStages, runOnLifecycle } from '@univerjs/core';import { createIdentifier } from '@wendellhu/redi';-import type { Observable } from 'rxjs';// eslint-disable-next-line ts/consistent-type-definitionsexport type INumfmtItem = {@@ -46,9 +45,7 @@ export interface INumfmtItemWithCache {parameters: number; // The parameter that was last calculated};pattern: string;- type: FormatType;}-export type IRefItem = INumfmtItem & { count: number; type: FormatType; pattern: string };export interface INumfmtService {getValue(@@ -58,21 +55,12 @@ export interface INumfmtService {col: number,model?: ObjectMatrix<INumfmtItem>): Nullable<INumfmtItemWithCache>;- getModel(unitId: string, subUnitId: string): Nullable<ObjectMatrix<INumfmtItem>>;setValues(unitId: string,subUnitId: string,- values: Array<{ ranges: IRange[]; pattern: string; type: FormatType }>+ values: Array<{ ranges: IRange[]; pattern: string }>): void;deleteValues(unitId: string, subUnitId: string, values: IRange[]): void;- getRefModel(unitId: string): Nullable<RefAlias<IRefItem, 'i' | 'pattern'>>;- modelReplace$: Observable<string>;- serialTimeToTimestamp: (v: number, is1900?: boolean) => number;-}--export interface ISnapshot {- model: Record<string, IObjectMatrixPrimitiveType<INumfmtItem>>;- refModel: IRefItem[];}export const INumfmtService = createIdentifier<INumfmtService>('INumfmtService');diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 80c2aa29e5..5706425d4c 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -865,6 +865,9 @@ importers:'@univerjs/engine-formula':specifier: workspace:*version: link:../engine-formula+ '@univerjs/engine-numfmt':+ specifier: workspace:*+ version: link:../engine-numfmt'@univerjs/engine-render':specifier: workspace:*version: link:../engine-render