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-thc5b5aef922bd
diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.tsindex 23338dfdcd..3bdb380731 100644--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts@@ -11,19 +11,19 @@ export class NumfmtController {this._plugin = plugin;}- getConfig(): ObjectMatrixPrimitiveType<NumfmtValue> {- return this._model.getNumfmtConfig();+ getConfig(sheetId: string): ObjectMatrixPrimitiveType<NumfmtValue> {+ return this._model.getNumfmtConfig(sheetId);}- getColor(row: number, column: number): string {- return this._model.getNumfmtColor(row, column);+ getColor(sheetId: string, row: number, column: number): string {+ return this._model.getNumfmtColor(sheetId, row, column);}- getValue(row: number, column: number): string {- return this._model.getNumfmtValue(row, column);+ getValue(sheetId: string, row: number, column: number): string {+ return this._model.getNumfmtValue(sheetId, row, column);}- setNumfmt(row: number, column: number, numfmt: string): void {- this._model.setNumfmtValue(row, column, numfmt);+ setNumfmt(sheetId: string, row: number, column: number, numfmt: string): void {+ this._model.setNumfmtValue(sheetId, row, column, numfmt);}}diff --git a/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.ts b/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.tsindex 1f8eb4c723..518ab853f4 100644--- a/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.ts+++ b/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.ts@@ -1 +1,10 @@-export function SetNumfmt(row: number, column: number) {}+import { Nullable, Workbook } from '@univer/core';+import { NumfmtPlugin } from '../../NumfmtPlugin';+import { NUMFMT_PLUGIN_NAME } from '../../Const/PLUGIN_NAME';++export function SetNumfmt(workbook: Workbook, sheetId: string, row: number, column: number) {+ const plugin: Nullable<NumfmtPlugin> = workbook.getContext().getPluginManager().getPluginByName(NUMFMT_PLUGIN_NAME);+ if (plugin) {+ plugin.getConfig(sheetId);+ }+}diff --git a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.tsindex e02b27ce62..99075e4d0c 100644--- a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts+++ b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts@@ -12,7 +12,7 @@ export interface NumfmtValue {}export class NumfmtModel {- protected _matrix: ObjectMatrix<NumfmtValue>;+ protected _sheetNumfmtMatrix: Map<string, ObjectMatrix<NumfmtValue>>;protected _calculate(primeval: NumfmtValue): void {if (primeval.change) {@@ -23,25 +23,22 @@ export class NumfmtModel {}}- constructor() {- this._matrix = new ObjectMatrix<NumfmtValue>();- }-- getNumfmtConfig(): ObjectMatrixPrimitiveType<NumfmtValue> {- return this._matrix.toJSON();+ protected _fmtMatrix(sheetId: string): ObjectMatrix<NumfmtValue> {+ let sheetNumfmtMatrix = this._sheetNumfmtMatrix.get(sheetId);+ if (sheetNumfmtMatrix) {+ return sheetNumfmtMatrix;+ }+ sheetNumfmtMatrix = new ObjectMatrix<NumfmtValue>();+ this._sheetNumfmtMatrix.set(sheetId, sheetNumfmtMatrix);+ return sheetNumfmtMatrix;}- setNumfmtValue(row: number, column: number, value: string): void {- this._matrix.setValue(row, column, {- numfmt: value,- change: true,- value: String(),- color: String(),- });+ constructor() {+ this._sheetNumfmtMatrix = new Map();}- getNumfmtValue(row: number, column: number): string {- const primeval = this._matrix.getValue(row, column);+ getNumfmtValue(sheetId: string, row: number, column: number): string {+ const primeval = this._fmtMatrix(sheetId).getValue(row, column);if (primeval) {this._calculate(primeval);return primeval.value;@@ -49,12 +46,25 @@ export class NumfmtModel {return String();}- getNumfmtColor(row: number, column: number): string {- const primeval = this._matrix.getValue(row, column);+ 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();}++ getNumfmtConfig(sheetId: string): ObjectMatrixPrimitiveType<NumfmtValue> {+ return this._fmtMatrix(sheetId).toJSON();+ }++ setNumfmtValue(sheetId: string, row: number, column: number, value: string): void {+ this._fmtMatrix(sheetId).setValue(row, column, {+ numfmt: value,+ change: true,+ value: String(),+ color: String(),+ });+ }}diff --git a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.tsindex 1f24f31a26..b7b45ef237 100644--- a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts+++ b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts@@ -9,23 +9,23 @@ export class NumfmtPlugin extends Plugin {super(NUMFMT_PLUGIN_NAME);}- onMounted(ctx: Context): void {+ onMounted(context: Context): void {this._controller = new NumfmtController(this);}- getConfig() {- this._controller.getConfig();+ getConfig(sheetId: string) {+ this._controller.getConfig(sheetId);}- getValue(row: number, column: number): string {- return this._controller.getValue(row, column);+ getValue(sheetId: string, row: number, column: number): string {+ return this._controller.getValue(sheetId, row, column);}- getColor(row: number, column: number): string {- return this._controller.getColor(row, column);+ getColor(sheetId: string, row: number, column: number): string {+ return this._controller.getColor(sheetId, row, column);}- setNumfmt(row: number, column: number, numfmt: string): void {- this._controller.setNumfmt(row, column, numfmt);+ setNumfmt(sheetId: string, row: number, column: number, numfmt: string): void {+ this._controller.setNumfmt(sheetId, row, column, numfmt);}}