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
chore(core): setRangeData,clear api
Dushusir6e7c8be386be
diff --git a/examples/univer-sheet-ts/scripts/color.ts b/examples/univer-sheet-ts/scripts/color.tsnew file mode 100644index 0000000000..2865ca1da3--- /dev/null+++ b/examples/univer-sheet-ts/scripts/color.ts@@ -0,0 +1,27 @@+// colors reference of text to command when running node.js application+// https://stackoverflow.com/a/41407246+export const Reset = '\x1b[0m';+export const Bright = '\x1b[1m';+export const Dim = '\x1b[2m';+export const Underscore = '\x1b[4m';+export const Blink = '\x1b[5m';+export const Reverse = '\x1b[7m';+export const Hidden = '\x1b[8m';++export const FgBlack = '\x1b[30m';+export const FgRed = '\x1b[31m';+export const FgGreen = '\x1b[32m';+export const FgYellow = '\x1b[33m';+export const FgBlue = '\x1b[34m';+export const FgMagenta = '\x1b[35m';+export const FgCyan = '\x1b[36m';+export const FgWhite = '\x1b[37m';++export const BgBlack = '\x1b[40m';+export const BgRed = '\x1b[41m';+export const BgGreen = '\x1b[42m';+export const BgYellow = '\x1b[43m';+export const BgBlue = '\x1b[44m';+export const BgMagenta = '\x1b[45m';+export const BgCyan = '\x1b[46m';+export const BgWhite = '\x1b[47m';diff --git a/examples/univer-sheet-ts/scripts/start.ts b/examples/univer-sheet-ts/scripts/start.tsindex 0df16fc96d..8cb2de6817 100644--- a/examples/univer-sheet-ts/scripts/start.ts+++ b/examples/univer-sheet-ts/scripts/start.ts@@ -1,6 +1,7 @@import * as esbuild from 'esbuild'import { commonBuildOptions, hasFolder, paths } from "./common";import { promises } from "fs";+import { Bright, FgCyan, FgGreen, Reset } from './color';(async () => {@@ -23,7 +24,7 @@ import { promises } from "fs";let url = `http://localhost:${port}`;- console.log('local server:', url);+ console.log(`${Bright}${FgGreen}Local server: ${FgCyan}${url}${Reset}`);var start =process.platform == "darwin"diff --git a/packages/core/src/Command/RegisterAction.ts b/packages/core/src/Command/RegisterAction.tsindex 90d86ad577..72e407bf19 100644--- a/packages/core/src/Command/RegisterAction.ts+++ b/packages/core/src/Command/RegisterAction.ts@@ -23,8 +23,6 @@ import {SetHiddenGridlinesAction,SetNamedRangeAction,SetRangeDataAction,- SetRangeFormatAction,- SetRangeFormulaAction,SetRangeNoteAction,SetRangeStyleAction,SetRangeFormattedValueAction,@@ -108,8 +106,6 @@ CommandManager.register(RemoveColumnAction.NAME, RemoveColumnAction);CommandManager.register(DeleteNamedRangeAction.NAME, DeleteNamedRangeAction);CommandManager.register(SetNamedRangeAction.NAME, SetNamedRangeAction);CommandManager.register(AddNamedRangeAction.NAME, AddNamedRangeAction);-CommandManager.register(SetRangeFormatAction.NAME, SetRangeFormatAction);-CommandManager.register(SetRangeFormulaAction.NAME, SetRangeFormulaAction);CommandManager.register(SetRangeNoteAction.NAME, SetRangeNoteAction);CommandManager.register(InsertSheetAction.NAME, InsertSheetAction);CommandManager.register(RemoveSheetAction.NAME, RemoveSheetAction);diff --git a/packages/core/src/Const/ACTION_NAMES.ts b/packages/core/src/Const/ACTION_NAMES.tsindex 47466505ed..33bade9cc2 100644--- a/packages/core/src/Const/ACTION_NAMES.ts+++ b/packages/core/src/Const/ACTION_NAMES.ts@@ -8,8 +8,6 @@ export enum ACTION_NAMES {INSERT_ROW_ACTION = 'InsertRowAction',REMOVE_ROW_ACTION = 'RemoveRowAction',SET_RANGE_STYLE_ACTION = 'SetRangeStyleAction',- SET_RANGE_FORMULA_ACTION = 'SetRangeFormulaAction',- SET_RANGE_FORMAT_ACTION = 'SetRangeFormatAction',SET_SELECTION_ACTION = 'SetSelectionActivateAction',SET_RANGE_DATA_ACTION = 'SetRangeDataAction',SET_RANGE_FORMATTED_VALUE_ACTION = 'SetRangeFormattedValueAction',diff --git a/packages/core/src/Interfaces/IRangeData.ts b/packages/core/src/Interfaces/IRangeData.tsindex 7de0c1f971..e01f34217c 100644--- a/packages/core/src/Interfaces/IRangeData.ts+++ b/packages/core/src/Interfaces/IRangeData.ts@@ -161,20 +161,6 @@ export interface IOptionData {* Whether to clear only the comments.*/}-/**- * Whether to clear only the contents.Whether to clear only data validation rules.Whether to avoid clearing filtered rows.- */-export interface IOptionsData extends IOptionData {- commentsOnly?: boolean;- /**- * Whether to clear only data validation rules.- */- validationsOnly?: boolean;- /**- * Whether to avoid clearing filtered rows.- */- skipFilteredRows?: boolean;-}/*** Option of copyTo functiondiff --git a/packages/core/src/Sheets/Action/ClearRangeAction.ts b/packages/core/src/Sheets/Action/ClearRangeAction.tsindex 74066049d6..dbad5ab509 100644--- a/packages/core/src/Sheets/Action/ClearRangeAction.ts+++ b/packages/core/src/Sheets/Action/ClearRangeAction.ts@@ -1,5 +1,5 @@import { ClearRangeApply, SetRangeDataApply } from '../Apply';-import { ICellData, IOptionsData, IRangeData } from '../../Interfaces';+import { ICellData, IOptionData, IRangeData } from '../../Interfaces';import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';@@ -10,7 +10,7 @@ import { CommandManager, CommandUnit } from '../../Command';* @internal*/export interface IClearRangeActionData extends ISheetActionData {- options: IOptionsData;+ options: IOptionData;rangeData: IRangeData;}diff --git a/packages/core/src/Sheets/Action/SetRangeDataAction.ts b/packages/core/src/Sheets/Action/SetRangeDataAction.tsindex 372e9e2c63..8ee12fc647 100644--- a/packages/core/src/Sheets/Action/SetRangeDataAction.ts+++ b/packages/core/src/Sheets/Action/SetRangeDataAction.ts@@ -1,4 +1,4 @@-import { SetRangeData, SetRangeDataApply } from '../Apply';+import { SetRangeDataApply } from '../Apply';import { ObjectMatrixPrimitiveType } from '../../Shared';import {SheetActionBase,@@ -81,11 +81,7 @@ export class SetRangeDataAction extends SheetActionBase<// actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,actionName: SetRangeDataAction.NAME,sheetId,- cellValue: SetRangeData(- worksheet.getCellMatrix(),- cellValue,- styles- ),+ cellValue: SetRangeDataApply(this._commandUnit, this._oldActionData),options,};diff --git a/packages/core/src/Sheets/Action/SetRangeFormatAction.ts b/packages/core/src/Sheets/Action/SetRangeFormatAction.tsdeleted file mode 100644index 4f854bfad6..0000000000--- a/packages/core/src/Sheets/Action/SetRangeFormatAction.ts+++ /dev/null@@ -1,106 +0,0 @@-import { SetRangeFormat } from '../Apply';-import { IRangeData } from '../../Interfaces';-import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';-import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';-import { ActionObservers, ActionType } from '../../Command/ActionObservers';-import { CommandManager, CommandUnit } from '../../Command';--/**- * @internal- */-export interface ISetRangeFormatActionData extends ISheetActionData {- cellFormat: ObjectMatrixPrimitiveType<string>;- rangeData: IRangeData;-}--/**- * @internal- */-export class SetRangeFormatAction extends SheetActionBase<- ISetRangeFormatActionData,- ISetRangeFormatActionData,- ObjectMatrixPrimitiveType<string>-> {- static NAME = 'SetRangeFormatAction';-- constructor(- actionData: ISetRangeFormatActionData,- commandUnit: CommandUnit,- observers: ActionObservers- ) {- super(actionData, commandUnit, observers);-- this._doActionData = {- ...actionData,- };- this._oldActionData = {- ...actionData,- cellFormat: this.do(),- };-- this.validate();- }-- do(): ObjectMatrixPrimitiveType<string> {- const worksheet = this.getWorkSheet();-- const result = SetRangeFormat(- worksheet.getCellMatrix(),- this._doActionData.cellFormat,- this._doActionData.rangeData- );-- this._observers.notifyObservers({- type: ActionType.REDO,- data: this._doActionData,- action: this,- });-- return result;- }-- redo(): void {- // update pre data- const { sheetId, rangeData } = this._doActionData;- this._oldActionData = {- // actionName: ACTION_NAMES.SET_RANGE_FORMAT_ACTION,- actionName: SetRangeFormatAction.NAME,- sheetId,- cellFormat: this.do(),- rangeData,- };- // this.do();- }-- undo(): void {- const { rangeData, sheetId, cellFormat } = this._oldActionData;- const worksheet = this.getWorkSheet();- if (worksheet) {- // update current data- this._doActionData = {- // actionName: ACTION_NAMES.SET_RANGE_FORMAT_ACTION,- actionName: SetRangeFormatAction.NAME,- sheetId,- cellFormat: SetRangeFormat(- worksheet.getCellMatrix(),- cellFormat,- rangeData- ),- rangeData,- };-- this._observers.notifyObservers({- type: ActionType.UNDO,- data: this._oldActionData,- action: this,- });- }- // SetRangeFormat(worksheet.getCellMatrix(), cellFormat, rangeData);- }-- validate(): boolean {- return false;- }-}--CommandManager.register(SetRangeFormatAction.NAME, SetRangeFormatAction);diff --git a/packages/core/src/Sheets/Action/SetRangeFormulaAction.ts b/packages/core/src/Sheets/Action/SetRangeFormulaAction.tsdeleted file mode 100644index a2788a9dec..0000000000--- a/packages/core/src/Sheets/Action/SetRangeFormulaAction.ts+++ /dev/null@@ -1,104 +0,0 @@-import { SetRangeFormula } from '../Apply';-import { IRangeData } from '../../Interfaces';-import { ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';-import { SheetActionBase, ISheetActionData } from '../../Command/SheetActionBase';-import { ActionObservers, ActionType } from '../../Command/ActionObservers';-import { CommandManager, CommandUnit } from '../../Command';--/**- * @internal- */-export interface ISetRangeFormulaActionData extends ISheetActionData {- cellFormula: ObjectMatrixPrimitiveType<string>;- rangeData: IRangeData;-}--/**- * @internal- */-export class SetRangeFormulaAction extends SheetActionBase<- ISetRangeFormulaActionData,- ISetRangeFormulaActionData,- ObjectMatrixPrimitiveType<string>-> {- static NAME = 'SetRangeFormulaAction';-- constructor(- actionData: ISetRangeFormulaActionData,- commandUnit: CommandUnit,- observers: ActionObservers- ) {- super(actionData, commandUnit, observers);-- this._doActionData = {- ...actionData,- };- this._oldActionData = {- ...actionData,- cellFormula: this.do(),- };-- this.validate();- }-- do(): ObjectMatrixPrimitiveType<string> {- const worksheet = this.getWorkSheet();-- const result = SetRangeFormula(- worksheet.getCellMatrix(),- this._doActionData.cellFormula,- this._doActionData.rangeData- );-- this._observers.notifyObservers({- type: ActionType.REDO,- data: this._doActionData,- action: this,- });-- return result;- }-- redo(): void {- // update pre data- const { sheetId, rangeData } = this._doActionData;- this._oldActionData = {- // actionName: ACTION_NAMES.SET_RANGE_FORMULA_ACTION,- actionName: SetRangeFormulaAction.NAME,- sheetId,- cellFormula: this.do(),- rangeData,- };- }-- undo(): void {- const { rangeData, sheetId, cellFormula } = this._oldActionData;- const worksheet = this.getWorkSheet();- if (worksheet) {- // update current data- this._doActionData = {- // actionName: ACTION_NAMES.SET_RANGE_FORMULA_ACTION,- actionName: SetRangeFormulaAction.NAME,- sheetId,- cellFormula: SetRangeFormula(- worksheet.getCellMatrix(),- cellFormula,- rangeData- ),- rangeData,- };-- this._observers.notifyObservers({- type: ActionType.UNDO,- data: this._oldActionData,- action: this,- });- }- }-- validate(): boolean {- return false;- }-}--CommandManager.register(SetRangeFormulaAction.NAME, SetRangeFormulaAction);diff --git a/packages/core/src/Sheets/Action/index.ts b/packages/core/src/Sheets/Action/index.tsindex 7adb48db4d..06b5afa1ee 100644--- a/packages/core/src/Sheets/Action/index.ts+++ b/packages/core/src/Sheets/Action/index.ts@@ -23,8 +23,6 @@ export * from './SetColumnWidthAction';export * from './SetHiddenGridlinesAction';export * from './SetNamedRangeAction';export * from './SetRangeDataAction';-export * from './SetRangeFormatAction';-export * from './SetRangeFormulaAction';export * from './SetRangeNoteAction';export * from './SetRangeStyleAction';export * from './SetRangeFormattedValueAction';diff --git a/packages/core/src/Sheets/Apply/ClearRange.ts b/packages/core/src/Sheets/Apply/ClearRange.tsindex c24f0ea4c2..4c3a4b25fc 100644--- a/packages/core/src/Sheets/Apply/ClearRange.ts+++ b/packages/core/src/Sheets/Apply/ClearRange.ts@@ -1,7 +1,8 @@-import { ICellData, IOptionsData, IRangeData } from '../../Interfaces';+import { ICellData, IOptionData, IRangeData } from '../../Interfaces';import { Tools, ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared';-import { CommandUnit, IClearRangeActionData } from '../../Command';+import { CommandUnit } from '../../Command';+import { IClearRangeActionData } from '../Action';/***@@ -14,7 +15,7 @@ import { CommandUnit, IClearRangeActionData } from '../../Command';*/export function ClearRange(cellMatrix: ObjectMatrix<ICellData>,- options: IOptionsData,+ options: IOptionData,rangeData: IRangeData): ObjectMatrixPrimitiveType<ICellData> {const { startRow, endRow, startColumn, endColumn } = rangeData;@@ -37,7 +38,6 @@ export function ClearRange(value.v = '';value.m = '';}- // TODO more optionscellMatrix.setValue(r, c, Tools.deepClone(value as ICellData));}@@ -70,7 +70,6 @@ export function ClearRangeApply(unit: CommandUnit, data: IClearRangeActionData)value.v = '';value.m = '';}- // TODO more optionscellMatrix?.setValue(r, c, Tools.deepClone(value as ICellData));}diff --git a/packages/core/src/Sheets/Apply/SetRangeData.ts b/packages/core/src/Sheets/Apply/SetRangeData.tsindex 0123f71017..4f25f3e7ca 100644--- a/packages/core/src/Sheets/Apply/SetRangeData.ts+++ b/packages/core/src/Sheets/Apply/SetRangeData.ts@@ -1,115 +1,9 @@-import { Styles } from '../Domain';-import { ICellData, ICopyToOptionsData, IStyleData } from '../../Interfaces';+import { ICellData, IStyleData } from '../../Interfaces';import { Nullable, Tools } from '../../Shared';-import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';+import { ObjectMatrix } from '../../Shared/ObjectMatrix';import { mergeStyle, transformStyle } from './SetRangeStyle';-import { CommandUnit, ISetRangeDataActionData } from '../../Command';--/**- *- * @param cellMatrix- * @param addMatrix- * @param rangeData- * @param options- * @returns- *- * @internal- */-export function SetRangeData(- cellMatrix: ObjectMatrix<ICellData>,- addMatrix: ObjectMatrixPrimitiveType<ICellData>,- styles: Styles,- options?: ICopyToOptionsData-): ObjectMatrixPrimitiveType<ICellData> {- let target = new ObjectMatrix(addMatrix);-- const result = new ObjectMatrix<ICellData>();-- if (options) {- target.forValue((r, c, value) => {- const cell = cellMatrix.getValue(r, c);- const newCell: ICellData = {};-- if (options.contentsOnly) {- newCell.m = cell?.m;- newCell.v = cell?.v;- }-- if (options.formatOnly) {- // newCell.f = cell?.f;- newCell.v = cell?.v;- newCell.m = cell?.m;- }-- result.setValue(r, c, newCell || {});-- cellMatrix.setValue(r, c, value || {});- });-- return result.getData();- }-- target.forValue((r, c, value) => {- const cell = cellMatrix.getValue(r, c) || {};-- // set null, clear cell- if (!value) {- cellMatrix.setValue(r, c, value);- result.setValue(r, c, cell);- } else {- // update style-- // use null to clear style- const old = styles.getStyleByCell(cell);-- // store old data- const oldCellStyle = transformStyle(- old,- value?.s as Nullable<IStyleData>- );- const oldCellData = Tools.deepClone(cell);- oldCellData.s = oldCellStyle;-- result.setValue(r, c, oldCellData);-- if (old == null) {- // clear- delete cell.s;- }-- // set style- const merge = mergeStyle(old, value?.s as Nullable<IStyleData>);-- // then remove null- merge && Tools.removeNull(merge);-- if (Tools.isEmptyObject(merge)) {- delete cell.s;- } else {- cell.s = styles.setValue(merge);- }-- // update other value TODO: move- // if (value.p != null) {- // cell.p = value.p;- // }- if (value.v != null) {- cell.v = value.v;- }- if (value.m != null) {- cell.m = value.m;- } else {- cell.m = String(cell.v);- }- if (value.t != null) {- cell.t = value.t;- }-- cellMatrix.setValue(r, c, cell);- }- });- return result.getData();-}+import { CommandUnit } from '../../Command';+import { ISetRangeDataActionData } from '../Action';export function SetRangeDataApply(unit: CommandUnit, data: ISetRangeDataActionData) {const workbook = unit.WorkBookUnit;diff --git a/packages/core/src/Sheets/Apply/SetRangeFormat.ts b/packages/core/src/Sheets/Apply/SetRangeFormat.tsdeleted file mode 100644index 0354030b5d..0000000000--- a/packages/core/src/Sheets/Apply/SetRangeFormat.ts+++ /dev/null@@ -1,99 +0,0 @@-import { ICellData, IRangeData } from '../../Interfaces';-import { Nullable, Tools } from '../../Shared';-import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';-import { CommandUnit, ISetRangeFormatActionData } from '../../Command';--/**- * TODO remove tp Format Plugin- */-/**- *- * @param cellMatrix- * @param addMatrix- * @param rangeData- * @returns- *- * @internal- */-export function SetRangeFormat(- cellMatrix: ObjectMatrix<ICellData>,- addMatrix: ObjectMatrixPrimitiveType<string>,- rangeData: IRangeData-): ObjectMatrixPrimitiveType<string> {- const target = new ObjectMatrix(addMatrix);- const result = new ObjectMatrix<string>();- for (let i = rangeData.startRow; i <= rangeData.endRow; i++) {- for (let j = rangeData.startColumn; j <= rangeData.endColumn; j++) {- const targetValue = target.getValue(i, j);-- if (targetValue) {- const value = JSON.parse(targetValue);-- // store history value- const cell: Nullable<ICellData> = cellMatrix.getValue(i, j);- // result.setValue(i, j, (cell && JSON.stringify(cell.fm)) || '');-- // update new value, cell may be undefined- const cellValue: ICellData = Tools.deepClone(cell || {});-- // cellValue.fm = {- // f: value.f,- // t: value.t,- // };-- cellMatrix.setValue(i, j, cellValue || {});- } else {- const cell: Nullable<ICellData> = cellMatrix.getValue(i, j);- // result.setValue(i, j, (cell && JSON.stringify(cell.fm)) || '');- const cellValue: ICellData = Tools.deepClone(cell || {});- // delete cellValue.fm;- cellMatrix.setValue(i, j, cellValue || {});- }- }- }- return result.getData();-}--export function SetRangeFormatApply(- unit: CommandUnit,- data: ISetRangeFormatActionData-) {- const workbook = unit.WorkBookUnit;- const worksheet = workbook!.getSheetBySheetId(data.sheetId)!;- const cellMatrix = worksheet.getCellMatrix();- const addMatrix = data.cellFormat;- const rangeData = data.rangeData;-- const target = new ObjectMatrix(addMatrix);- const result = new ObjectMatrix<string>();- for (let i = rangeData.startRow; i <= rangeData.endRow; i++) {- for (let j = rangeData.startColumn; j <= rangeData.endColumn; j++) {- const targetValue = target.getValue(i, j);-- if (targetValue) {- const value = JSON.parse(targetValue);-- // store history value- const cell: Nullable<ICellData> = cellMatrix.getValue(i, j);- // result.setValue(i, j, (cell && JSON.stringify(cell.fm)) || '');-- // update new value, cell may be undefined- const cellValue: ICellData = Tools.deepClone(cell || {});-- // cellValue.fm = {- // f: value.f,- // t: value.t,- // };-- cellMatrix.setValue(i, j, cellValue || {});- } else {- const cell: Nullable<ICellData> = cellMatrix.getValue(i, j);- // result.setValue(i, j, (cell && JSON.stringify(cell.fm)) || '');- const cellValue: ICellData = Tools.deepClone(cell || {});- // delete cellValue.fm;- cellMatrix.setValue(i, j, cellValue || {});- }- }- }- return result.getData();-}diff --git a/packages/core/src/Sheets/Apply/SetRangeFormattedValue.ts b/packages/core/src/Sheets/Apply/SetRangeFormattedValue.tsindex d4b1b447b2..6c4f5978bf 100644--- a/packages/core/src/Sheets/Apply/SetRangeFormattedValue.ts+++ b/packages/core/src/Sheets/Apply/SetRangeFormattedValue.ts@@ -1,7 +1,8 @@import { ICellData, ICellV, IRangeData } from '../../Interfaces';import { Nullable, Tools } from '../../Shared';import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';-import { CommandUnit, ISetRangeFormattedValueActionData } from '../../Command';+import { CommandUnit } from '../../Command';+import { ISetRangeFormattedValueActionData } from '../Action';/***diff --git a/packages/core/src/Sheets/Apply/SetRangeFormula.ts b/packages/core/src/Sheets/Apply/SetRangeFormula.tsdeleted file mode 100644index 54073a161f..0000000000--- a/packages/core/src/Sheets/Apply/SetRangeFormula.ts+++ /dev/null@@ -1,74 +0,0 @@-import { ICellData, IRangeData } from '../../Interfaces';-import { Nullable, Tools } from '../../Shared';-import { ObjectMatrix, ObjectMatrixPrimitiveType } from '../../Shared/ObjectMatrix';-import { CommandUnit, ISetRangeFormulaActionData } from '../../Command';--/**- * TODO remove tp Formula Plugin- */--/**- *- * @param cellMatrix- * @param addMatrix- * @param rangeData- * @returns- *- * @internal- */-export function SetRangeFormula(- cellMatrix: ObjectMatrix<ICellData>,- addMatrix: ObjectMatrixPrimitiveType<string>,- rangeData: IRangeData-): ObjectMatrixPrimitiveType<string> {- const target = new ObjectMatrix(addMatrix);- const result = new ObjectMatrix<string>();- for (let i = rangeData.startRow; i <= rangeData.endRow; i++) {- for (let j = rangeData.startColumn; j <= rangeData.endColumn; j++) {- const value = target.getValue(i, j);-- // store history value- const cell: Nullable<ICellData> = cellMatrix.getValue(i, j);- // result.setValue(i, j, (cell && cell.f) || '');-- // update new value, cell may be undefined- const cellValue = Tools.deepClone(cell || {});-- cellValue.f = value;-- cellMatrix.setValue(i, j, cellValue || {});- }- }- return result.getData();-}--export function SetRangeFormulaApply(- unit: CommandUnit,- data: ISetRangeFormulaActionData-) {- const workbook = unit.WorkBookUnit;- const worksheet = workbook!.getSheetBySheetId(data.sheetId)!;- const cellMatrix = worksheet.getCellMatrix();- const addMatrix = data.cellFormula;- const rangeData = data.rangeData;-- const target = new ObjectMatrix(addMatrix);- const result = new ObjectMatrix<string>();- for (let i = rangeData.startRow; i <= rangeData.endRow; i++) {- for (let j = rangeData.startColumn; j <= rangeData.endColumn; j++) {- const value = target.getValue(i, j);-- // store history value- const cell: Nullable<ICellData> = cellMatrix.getValue(i, j);- // result.setValue(i, j, (cell && cell.f) || '');-- // update new value, cell may be undefined- const cellValue = Tools.deepClone(cell || {});-- cellValue.f = value;-- cellMatrix.setValue(i, j, cellValue || {});- }- }- return result.getData();-}diff --git a/packages/core/src/Sheets/Apply/index.ts b/packages/core/src/Sheets/Apply/index.tsindex f53ccc3831..a34b17333e 100644--- a/packages/core/src/Sheets/Apply/index.ts+++ b/packages/core/src/Sheets/Apply/index.ts@@ -25,8 +25,6 @@ export * from './SetHiddenGridlines';export * from './SetHideRows';export * from './SetNamedRange';export * from './SetRangeData';-export * from './SetRangeFormat';-export * from './SetRangeFormula';export * from './SetRangeNote';export * from './SetRangeStyle';export * from './SetRangeFormattedValue';diff --git a/packages/core/src/Sheets/Domain/Range.ts b/packages/core/src/Sheets/Domain/Range.tsindex f27367aae1..b41714a6de 100644--- a/packages/core/src/Sheets/Domain/Range.ts+++ b/packages/core/src/Sheets/Domain/Range.ts@@ -7,7 +7,6 @@ import {IRemoveMergeActionData,IDeleteRangeActionData,ISetRangeDataActionData,- ISetRangeFormulaActionData,ISetRangeStyleActionData,ISetRangeFormattedValueActionData,SetRangeStyleAction,@@ -41,7 +40,6 @@ import {ICellV,IDocumentData,IOptionData,- IOptionsData,IRangeData,IRangeType,IStyleData,@@ -1148,73 +1146,6 @@ export class Range {return this;}- /**- * Updates the formula for this range.- *- * @param formula A string representing the formula to set for the cell.- * @returns This range, for chaining.- */- setFormula(formula: string): Range {- const { _rangeData, _context, _commandManager, _worksheet } = this;- const { startRow, startColumn, endRow, endColumn } = _rangeData;- const cellValue = new ObjectMatrix<string>();- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- cellValue.setValue(r, c, formula);- }- }- const setValue: ISetRangeFormulaActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_FORMULA_ACTION,- cellFormula: cellValue.getData(),- rangeData: this._rangeData,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);-- return this;- }-- /**- * Sets a rectangular grid of formulas (must match dimensions of this range).- *- * @param formulas A two-dimensional string array of formulas.- * @returns This range, for chaining.- */- setFormulas(formulas: string[][]): Range {- const { _rangeData, _context, _commandManager, _worksheet } = this;-- const { startRow, startColumn, endRow, endColumn } = _rangeData;-- const cellValue = new ObjectMatrix<string>();- for (let r = 0; r <= endRow - startRow; r++) {- for (let c = 0; c <= endColumn - startColumn; c++) {- cellValue.setValue(r + startRow, c + startColumn, formulas[r][c]);- }- }-- const setValue: ISetRangeFormulaActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_FORMULA_ACTION,- cellFormula: cellValue.getData(),- rangeData: this._rangeData,- };- const command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- setValue- );- _commandManager.invoke(command);-- return this;- }-/*** Sets a rectangular grid of horizontal alignments.*@@ -3269,11 +3200,11 @@ export class Range {*/clear(): Range;/**- * Clears the range of contents, format, data validation rules, and/or comments, as specified with the given advanced options. By default all data is cleared.+ * Clears the range of contents and/or format, as specified with the given advanced options. By default all data is cleared.* @param options A JavaScript object that specifies advanced parameters, as listed below.* @returns This range, for chaining.*/- clear(options: IOptionsData): Range;+ clear(options: IOptionData): Range;clear(...argument: any): Range {const { _context, _worksheet, _commandManager, _rangeData } = this;@@ -3323,15 +3254,6 @@ export class Range {return this.clear({ contentsOnly: true });}- /**- * Clears the note in the given cell or cells.- *- * @returns Range This range, for chaining.- */- clearNote(): Range {- return this.clear({ commentsOnly: true });- }-/*** Deletes this range of cells. Existing data in the sheet along the provided dimension is shifted towards the deleted range.*diff --git a/packages/core/src/Sheets/Domain/RangeList.ts b/packages/core/src/Sheets/Domain/RangeList.tsindex 5c3cef6896..a6b8a7b4e2 100644--- a/packages/core/src/Sheets/Domain/RangeList.ts+++ b/packages/core/src/Sheets/Domain/RangeList.ts@@ -11,7 +11,7 @@ import {import {ICellData,ICellV,- IOptionsData,+ IOptionData,IRangeData,IRangeType,IStyleData,@@ -24,7 +24,6 @@ import {IClearRangeActionData,ISetRangeDataActionData,ISetRangeFormattedValueActionData,- ISetRangeFormulaActionData,ISetRangeStyleActionData,SetRangeDataAction,SetRangeStyleAction,@@ -151,12 +150,12 @@ export class RangeList {clear(): RangeList;/**- * Clears the range of contents, format, data validation rules, and comments, as specified with the given options. By default all data is cleared.+ * Clears the range of contents and format, as specified with the given options. By default all data is cleared.*- * @param options A JavaScript object that specifies advanced parameters, as listed IOptionsData.+ * @param options A JavaScript object that specifies advanced parameters, as listed IOptionData.* @returns This range list, for chaining.*/- clear(options: IOptionsData): RangeList;+ clear(options: IOptionData): RangeList;clear(...argument: any): RangeList {const { _context, _worksheet, _commandManager, _rangeList } = this;@@ -164,9 +163,6 @@ export class RangeList {let options = {formatOnly: true,contentsOnly: true,- commentsOnly: true,- validationsOnly: true,- skipFilteredRows: true,};if (Tuples.checkup(argument, Tuples.OBJECT_TYPE)) {options = argument[0];@@ -446,45 +442,6 @@ export class RangeList {return this._setStyle(fontBoolean, 'bl');}- /**- * Updates the formula for each Range in the range list.- *- * @param formula A string representing the formula to set.- * @returns This range list, for chaining.- */- setFormula(formula: string): RangeList {- let { _rangeList, _context, _commandManager, _worksheet } = this;-- const setList = _rangeList.map((range) => {- let { startRow, startColumn, endRow, endColumn } = range;-- let cellValue = new ObjectMatrix<string>();- for (let r = startRow; r <= endRow; r++) {- for (let c = startColumn; c <= endColumn; c++) {- cellValue.setValue(r, c, formula);- }- }-- let setValue: ISetRangeFormulaActionData = {- sheetId: _worksheet.getSheetId(),- actionName: ACTION_NAMES.SET_RANGE_FORMULA_ACTION,- cellFormula: cellValue.getData(),- rangeData: range,- };-- return setValue;- });-- let command = new Command(- {- WorkBookUnit: _context.getWorkBook(),- },- ...setList- );- _commandManager.invoke(command);- return this;- }-/*** Set the horizontal alignment for each Range in the range list.*