Skip to content

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.

feat(sheet-numfmt-plugin):numfmt plugin optimization

eiji-thd7630ed94579
diff --git a/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.ts b/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.ts
index 518ab853f4..182ef0e322 100644
--- a/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.ts
+++ b/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.ts
@@ -1,10 +1,17 @@
-import { Nullable, Workbook } from '@univer/core';
+import { Nullable, ObjectMatrix, 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);
+export function SetNumfmt(workbook: Workbook, sheetId: string, row: number, column: number, value: string) {
+ const numfmtPlugin: Nullable<NumfmtPlugin> = workbook.getContext().getPluginManager().getPluginByName(NUMFMT_PLUGIN_NAME);
+ if (numfmtPlugin) {
+ const primitive = numfmtPlugin.getConfig(sheetId);
+ const matrix = new ObjectMatrix(primitive);
+ matrix.setValue(row, column, {
+ numfmt: value,
+ change: true,
+ value: String(),
+ color: String(),
+ });
}
}
diff --git a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts
index 569df1edf8..f931a5774e 100644
--- a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts
+++ b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts
@@ -55,13 +55,4 @@ export class NumfmtModel {
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.ts
index b7b45ef237..f1a78d8d62 100644
--- a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts
+++ b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts
@@ -1,6 +1,7 @@
-import { Context, Plugin } from '@univer/core';
+import { Context, ObjectMatrixPrimitiveType, Plugin } from '@univer/core';
import { NUMFMT_PLUGIN_NAME } from './Const/PLUGIN_NAME';
import { NumfmtController } from './Controller/NumfmtController';
+import { NumfmtValue } from './Model/NumfmtModel';
export class NumfmtPlugin extends Plugin {
protected _controller: NumfmtController;
@@ -13,8 +14,8 @@ export class NumfmtPlugin extends Plugin {
this._controller = new NumfmtController(this);
}
- getConfig(sheetId: string) {
- this._controller.getConfig(sheetId);
+ getConfig(sheetId: string): ObjectMatrixPrimitiveType<NumfmtValue> {
+ return this._controller.getConfig(sheetId);
}
getValue(sheetId: string, row: number, column: number): string {