本帖最后由 Joestar.Xu 于 2024-5-22 12:07 编辑
您好,抱歉之前给出的信息有误,请参考以下代码:
之前的版主链接:https://gcdn.grapecity.com.cn/showtopic-162581-1-1.html
- var command1 = {
- canUndo: true,
- execute: function (spread, options, isUndo) {
- var Commands = GC.Spread.Sheets.Commands;
- options.cmd = "sheetCmd";
- if (isUndo) {
- Commands.undoTransaction(spread, options);
- return true;
- } else {
- Commands.startTransaction(spread, options);
- var sheet1 = spread.getSheetFromName(options.sheetName[0]);
- let cell = sheet1.getCell(options.row, options.col);
- cell.backColor(options.backColor);
- sheet1.addRows(0, 1);
- var sheet = spread.getSheet(1);
- sheet.setValue(0, 0, "Hello, SpreadJS");
- Commands.endTransaction(spread, options);
- return true;
- }
- },
- };
- var commandManager = spread.commandManager();
- commandManager.register("sheetCmd", command1);
- document.querySelector("#button1").addEventListener("click", function () {
- commandManager.execute({
- cmd: "sheetCmd",
- sheetName: ["Sheet1", "Sheet2"],
- row: 1,
- col: 2,
- backColor: "red",
- });
- });
复制代码
|