fix(formula): fix cell custom properties would trigger formula calculation (#6408)

This commit is contained in:
wpxp123456
2025-12-31 14:42:58 +08:00
committed by GitHub
parent b6222ce051
commit 34711d9dfc
5 changed files with 137 additions and 7 deletions
@@ -48,6 +48,7 @@ import {
InsertSheetMutation,
RemoveSheetMutation,
SetBorderCommand,
SetRangeCustomMetadataCommand,
SetRangeValuesMutation,
SetStyleCommand,
SheetInterceptorService,
@@ -115,7 +116,8 @@ export class UpdateFormulaController extends Disposable {
(options && options.syncOnly === true) ||
params.trigger === SetStyleCommand.id ||
params.trigger === SetBorderCommand.id ||
params.trigger === ClearSelectionFormatCommand.id
params.trigger === ClearSelectionFormatCommand.id ||
params.trigger === SetRangeCustomMetadataCommand.id
) {
return;
}
@@ -0,0 +1,70 @@
/**
* Copyright 2023-present DreamNum Co., Ltd.
*
* 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 { CustomData, IAccessor, ICellData, ICommand, IRange } from '@univerjs/core';
import type { ISheetCommandSharedParams } from '../utils/interface';
import {
CommandType,
ICommandService,
IUniverInstanceService,
ObjectMatrix,
Tools,
} from '@univerjs/core';
import { SetRangeValuesMutation } from '../mutations/set-range-values.mutation';
import { getSheetCommandTarget } from './utils/target-util';
interface ICustomMetadata {
custom: CustomData;
};
export interface ISetRangeCustomMetadataCommandParams extends Partial<ISheetCommandSharedParams> {
range: IRange;
customMetadata: ICustomMetadata | ICustomMetadata[][];
}
/**
* The command to set custom metadata for a range of cells, and not support undo/redo.
*/
export const SetRangeCustomMetadataCommand: ICommand = {
id: 'sheet.command.set-range-custom-metadata',
type: CommandType.COMMAND,
handler: (accessor: IAccessor, params: ISetRangeCustomMetadataCommandParams) => {
const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
if (!target) return false;
const commandService = accessor.get(ICommandService);
const { unitId, subUnitId } = target;
const { range, customMetadata } = params;
const { startRow, startColumn, endRow, endColumn } = range;
const isArray = Tools.isArray(customMetadata);
const cellValue = new ObjectMatrix<ICellData>();
for (let r = startRow; r <= endRow; r++) {
for (let c = startColumn; c <= endColumn; c++) {
const value = isArray ? (customMetadata as ICustomMetadata[][])[r - startRow][c - startColumn] : (customMetadata as ICustomMetadata);
cellValue.setValue(r, c, value);
}
}
return commandService.syncExecuteCommand(SetRangeValuesMutation.id, {
unitId,
subUnitId,
cellValue: cellValue.getMatrix(),
});
},
};
@@ -74,6 +74,7 @@ import { SetDefinedNameCommand } from '../commands/commands/set-defined-name.com
import { CancelFrozenCommand, SetFrozenCommand } from '../commands/commands/set-frozen.command';
import { SetGridlinesColorCommand } from '../commands/commands/set-gridlines-color.command';
import { SetProtectionCommand } from '../commands/commands/set-protection.command';
import { SetRangeCustomMetadataCommand } from '../commands/commands/set-range-custom-metadata.command';
import { SetRangeValuesCommand } from '../commands/commands/set-range-values.command';
import { SetRowDataCommand } from '../commands/commands/set-row-data.command';
import {
@@ -275,6 +276,7 @@ export class BasicWorksheetController extends Disposable implements IDisposable
SetFrozenMutation,
CancelFrozenCommand,
SetHorizontalTextAlignCommand,
SetRangeCustomMetadataCommand,
SetRangeValuesCommand,
SetRowHeightCommand,
SetRowHiddenCommand,
+61 -6
View File
@@ -15,13 +15,50 @@
*/
import type { AbsoluteRefType, BorderStyleTypes, BorderType, CellValue, CustomData, ICellData, IColorStyle, IDocumentData, IObjectMatrixPrimitiveType, IRange, IStyleData, ITextDecoration, Nullable, Workbook, Worksheet } from '@univerjs/core';
import type { ISetBorderBasicCommandParams, ISetHorizontalTextAlignCommandParams, ISetRangeValuesCommandParams, ISetSelectionsOperationParams, ISetStyleCommandParams, ISetTextRotationCommandParams, ISetTextWrapCommandParams, ISetVerticalTextAlignCommandParams, IStyleTypeValue, SplitDelimiterEnum } from '@univerjs/sheets';
import type {
ISetBorderBasicCommandParams,
ISetHorizontalTextAlignCommandParams,
ISetRangeCustomMetadataCommandParams,
ISetRangeValuesCommandParams,
ISetSelectionsOperationParams,
ISetStyleCommandParams,
ISetTextRotationCommandParams,
ISetTextWrapCommandParams,
ISetVerticalTextAlignCommandParams,
IStyleTypeValue,
SplitDelimiterEnum,
} from '@univerjs/sheets';
import type { IFacadeClearOptions } from './f-worksheet';
import type { FHorizontalAlignment, FVerticalAlignment } from './utils';
import { BooleanNumber, covertCellValue, covertCellValues, DEFAULT_STYLES, Dimension, ICommandService, Inject, Injector, isNullCell, Rectangle, RichTextValue, TextStyleValue, WrapStrategy } from '@univerjs/core';
import { FBaseInitialable } from '@univerjs/core/facade';
import { FormulaDataModel, serializeRange, serializeRangeWithSheet } from '@univerjs/engine-formula';
import { addMergeCellsUtil, ClearSelectionAllCommand, ClearSelectionContentCommand, ClearSelectionFormatCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeleteWorksheetRangeThemeStyleCommand, getAddMergeMutationRangeByType, getPrimaryForRange, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, RemoveWorksheetMergeCommand, SetBorderBasicCommand, SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetSelectionsOperation, SetStyleCommand, SetTextRotationCommand, SetTextWrapCommand, SetVerticalTextAlignCommand, SetWorksheetRangeThemeStyleCommand, SheetRangeThemeService, SplitTextToColumnsCommand } from '@univerjs/sheets';
import {
addMergeCellsUtil,
ClearSelectionAllCommand,
ClearSelectionContentCommand,
ClearSelectionFormatCommand,
DeleteRangeMoveLeftCommand,
DeleteRangeMoveUpCommand,
DeleteWorksheetRangeThemeStyleCommand,
getAddMergeMutationRangeByType,
getPrimaryForRange,
InsertRangeMoveDownCommand,
InsertRangeMoveRightCommand,
RemoveWorksheetMergeCommand,
SetBorderBasicCommand,
SetHorizontalTextAlignCommand,
SetRangeCustomMetadataCommand,
SetRangeValuesCommand,
SetSelectionsOperation,
SetStyleCommand,
SetTextRotationCommand,
SetTextWrapCommand,
SetVerticalTextAlignCommand,
SetWorksheetRangeThemeStyleCommand,
SheetRangeThemeService,
SplitTextToColumnsCommand,
} from '@univerjs/sheets';
import { FWorkbook } from './f-workbook';
import { FWorksheet } from './f-worksheet';
import { FRangePermission } from './permission/f-range-permission';
@@ -946,9 +983,18 @@ export class FRange extends FBaseInitialable {
* ```
*/
setCustomMetaData(data: CustomData): FRange {
return this.setValue({
custom: data,
});
const params: ISetRangeCustomMetadataCommandParams = {
unitId: this._workbook.getUnitId(),
subUnitId: this._worksheet.getSheetId(),
range: this._range,
customMetadata: {
custom: data,
},
};
this._commandService.syncExecuteCommand(SetRangeCustomMetadataCommand.id, params);
return this;
}
/**
@@ -967,7 +1013,16 @@ export class FRange extends FBaseInitialable {
* ```
*/
setCustomMetaDatas(datas: CustomData[][]): FRange {
return this.setValues(datas.map((row) => row.map((data) => ({ custom: data }))));
const params: ISetRangeCustomMetadataCommandParams = {
unitId: this._workbook.getUnitId(),
subUnitId: this._worksheet.getSheetId(),
range: this._range,
customMetadata: datas.map((row) => row.map((data) => ({ custom: data }))),
};
this._commandService.syncExecuteCommand(SetRangeCustomMetadataCommand.id, params);
return this;
}
/**
+1
View File
@@ -137,6 +137,7 @@ export { type ICancelFrozenCommandParams, type ISetFrozenCommandParams } from '.
export { CancelFrozenCommand, SetFrozenCommand } from './commands/commands/set-frozen.command';
export { type ISetGridlinesColorCommandParams, SetGridlinesColorCommand } from './commands/commands/set-gridlines-color.command';
export { SetProtectionCommand } from './commands/commands/set-protection.command';
export { type ISetRangeCustomMetadataCommandParams, SetRangeCustomMetadataCommand } from './commands/commands/set-range-custom-metadata.command';
export { type ISetRangeValuesCommandParams, SetRangeValuesCommand } from './commands/commands/set-range-values.command';
export { type ISetRowDataCommandParams, SetRowDataCommand } from './commands/commands/set-row-data.command';
export {