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(sheet-numfmt-plugin):numfmt plugin optimization
eiji-thea47bb5c0d6e
diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.tsindex e04b307b9b..1eaae2b91d 100644--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts@@ -1,6 +1,6 @@-import { Command, Range, IRangeData, ObjectMatrix, ObjectMatrixPrimitiveType, Plugin } from '@univer/core';+import { Command, Range, IRangeData, ObjectMatrix, Plugin } from '@univer/core';import { ACTION_NAMES } from '../Const';-import { NumfmtModel, NumfmtValue } from '../Model/NumfmtModel';+import { NumfmtModel } from '../Model/NumfmtModel';export class NumfmtController {protected _model: NumfmtModel;@@ -12,23 +12,12 @@ export class NumfmtController {this._plugin = plugin;}- getConfig(sheetId: string): ObjectMatrixPrimitiveType<NumfmtValue> {- return this._model.getNumfmtConfig(sheetId);- }-- getColor(sheetId: string, row: number, column: number): string {- return this._model.getNumfmtColor(sheetId, row, column);- }-- getValue(sheetId: string, row: number, column: number): string {- return this._model.getNumfmtValue(sheetId, row, column);- }-setNumfmtByRange(sheetId: string, numfmtRange: IRangeData, numfmtValue: string): void {const numfmtMatrix = new ObjectMatrix<string>();Range.foreach(numfmtRange, (row, column) => {numfmtMatrix.setValue(row, column, numfmtValue);});+ this._model.setNumfmtMatrix(sheetId, numfmtMatrix);const pluginContext = this._plugin.getContext();const commandManager = pluginContext.getCommandManager();const config = {@@ -42,6 +31,7 @@ export class NumfmtController {}setNumfmtByCoords(sheetId: string, row: number, column: number, numfmt: string): void {+ this._model.setNumfmtCoords(sheetId, row, column, numfmt);const pluginContext = this._plugin.getContext();const commandManager = pluginContext.getCommandManager();const config = {diff --git a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.tsindex f931a5774e..e67c056a12 100644--- a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts+++ b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts@@ -1,31 +1,14 @@-import { ObjectMatrix, ObjectMatrixPrimitiveType } from '@univer/core';-import { numfmt } from '@univer/base-numfmt-engine';--export interface NumfmtValue {- numfmt: string;- color: string;- value: string;- change: boolean;-}+import { ObjectMatrix } from '@univer/core';export class NumfmtModel {- protected _sheetNumfmtMatrix: Map<string, ObjectMatrix<NumfmtValue>>;-- protected _calculate(primeval: NumfmtValue): void {- if (primeval.change) {- const formatter = numfmt(primeval.numfmt);- primeval.value = formatter(primeval.value);- primeval.color = formatter.color(primeval.value);- primeval.change = false;- }- }+ protected _sheetNumfmtMatrix: Map<string, ObjectMatrix<string>>;- protected _fmtMatrix(sheetId: string): ObjectMatrix<NumfmtValue> {+ protected _fromMatrix(sheetId: string): ObjectMatrix<string> {let sheetNumfmtMatrix = this._sheetNumfmtMatrix.get(sheetId);if (sheetNumfmtMatrix) {return sheetNumfmtMatrix;}- sheetNumfmtMatrix = new ObjectMatrix<NumfmtValue>();+ sheetNumfmtMatrix = new ObjectMatrix<string>();this._sheetNumfmtMatrix.set(sheetId, sheetNumfmtMatrix);return sheetNumfmtMatrix;}@@ -34,25 +17,15 @@ export class NumfmtModel {this._sheetNumfmtMatrix = new Map();}- getNumfmtValue(sheetId: string, row: number, column: number): string {- const primeval = this._fmtMatrix(sheetId).getValue(row, column);- if (primeval) {- this._calculate(primeval);- return primeval.value;- }- return String();- }-- getNumfmtColor(sheetId: string, row: number, column: number): string {- const primeval = this._fmtMatrix(sheetId).getValue(row, column);- if (primeval) {- this._calculate(primeval);- return primeval.color;- }- return String();+ setNumfmtMatrix(sheetId: string, matrix: ObjectMatrix<string>): void {+ const numfmtMatrix = this._fromMatrix(sheetId);+ matrix.forValue((row: number, col: number, numfmt) => {+ numfmtMatrix.setValue(row, col, numfmt);+ });}- getNumfmtConfig(sheetId: string): ObjectMatrixPrimitiveType<NumfmtValue> {- return this._fmtMatrix(sheetId).toJSON();+ setNumfmtCoords(sheetId: string, row: number, col: number, numfmt: string): void {+ const numfmtMatrix = this._fromMatrix(sheetId);+ numfmtMatrix.setValue(row, col, numfmt);}}diff --git a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.tsindex 7ac8d1f461..5d855830fe 100644--- a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts+++ b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts@@ -19,7 +19,9 @@ export class NumfmtPlugin extends Plugin {register.add(new NumfmtActionExtensionFactory(this));}- setNumfmtByRange(sheetId: string, range: IRangeData, format: string): void {}+ setNumfmtByRange(sheetId: string, range: IRangeData, format: string): void {+ this._controller.setNumfmtByRange(sheetId, range, format);+ }setNumfmtByCoords(sheetId: string, row: number, column: number, format: string): void {this._controller.setNumfmtByCoords(sheetId, row, column, format);