我做了一个简单的Demo,你可以参考一下:
window.onload = function () {
let designerConfig = JSON.parse(
JSON.stringify(GC.Spread.Sheets.Designer.DefaultConfig)
);
console.log(designerConfig);
designerConfig.commandMap = {
MyClear: {
text: "MyClear",
commandName: "MyClear",
iconClass: "none",
execute: async (context, propertyName, fontItalicChecked) => {
console.log("clear");
let spread = context.getWorkbook();
let sheet = spread.getActiveSheet();
let selections = sheet.getSelections();
let range = sheet.getRange(
selections[0].row,
selections[0].col,
selections[0].rowCount,
selections[0].colCount
);
range.setStyle(new GC.Spread.Sheets.Style());
range.formatter(null);
},
},
};
designerConfig.ribbon[0].buttonGroups[7].commandGroup.children[0].children[2].children.push(
"MyClear"
);
let designer = new GC.Spread.Sheets.Designer.Designer(
"gc-designer-container",
designerConfig
);
let spread = designer.getWorkbook();
let sheet = spread.getActiveSheet();
sheet.getCell(0, 0).value("Hello World");
};
效果如下:
|