本帖最后由 Lynn.Dou 于 2023-5-15 14:36 编辑
可以的,通过重写插入图表这个指令,判断选取的区域是否全为空,如果全为空则提示用户无法插入,请参考以下代码:
const container = document.getElementById('gc-designer-container') as HTMLDivElement;
let designerConfig = JSON.parse(JSON.stringify(GCD.Spread.Sheets.Designer.DefaultConfig));
let newCommand = GCD.Spread.Sheets.Designer.getCommand(
GCD.Spread.Sheets.Designer.CommandNames.InsertChart
);
if (newCommand) {
let oldExecute = newCommand.execute;
newCommand.execute = function (context: any, propertyName: any, args: any) {
let activeSheet = context.getWorkbook().getActiveSheet() as GC.Spread.Sheets.Worksheet;
let sel = activeSheet.getSelections()[0];
for (let i = sel.row; i < sel.rowCount; i++) {
for (let j = sel.col; j < sel.colCount; j++) {
if (sheet.getCell(i, j).value() !== null) {
oldExecute.call(this, context, propertyName, args);
return;
}
}
}
alert('Could not insert chart, please select a cell with value.');
};
}
designerConfig.commandMap = {};
designerConfig.commandMap[GCD.Spread.Sheets.Designer.CommandNames.InsertChart] = newCommand;
let designer = new GCD.Spread.Sheets.Designer.Designer(container, designerConfig);
效果如下:
-----------------------------------------------------
更新进展:
此问题已在V16.1.0修复,目前官网暂未正式发布,您可以先通过npm升级测试下
|