您好,这边调研了一下,您可以参考下面的代码来实现:
- window.onload = function () {
- let designerConfig = JSON.parse(
- JSON.stringify(GC.Spread.Sheets.Designer.DefaultConfig)
- );
- let designer = new GC.Spread.Sheets.Designer.Designer(
- "gc-designer-container",
- designerConfig
- );
- let spread = designer.getWorkbook();
- spread.setSheetCount(2);
- let sheet = spread.getActiveSheet();
- sheet.setValue(0, 0, 1);
- sheet.setValue(1, 0, 2);
- sheet.setValue(2, 0, 3);
- sheet.setFormula(0, 1, "=SUM(A1:A3)");
- let flag;
- const editingFormula = {};
- document.querySelector("#button1").addEventListener("click", function () {
- console.log("stop calcService");
- let spread = designer.getWorkbook();
- let sheet = spread.getActiveSheet();
- sheet.bind(GC.Spread.Sheets.Events.CellChanged, function (e, info) {
- if (info.propertyName == "formula") {
- if (flag) {
- flag = false;
- return;
- }
- let key = `${info.row},${info.col}`;
- if (editingFormula[key]) {
- editingFormula[key].data = info.text;
- } else {
- editingFormula[key] = {
- row: info.row,
- col: info.col,
- data: info.newValue,
- };
- }
- flag = true;
- sheet.setFormula(info.row, info.col, null);
- sheet.setValue(info.row, info.col, null);
- }
- });
- });
- document.querySelector("#button2").addEventListener("click", function () {
- console.log("resume calcService");
- let spread = designer.getWorkbook();
- let sheet = spread.getActiveSheet();
- sheet.unbind(GC.Spread.Sheets.Events.CellChanged);
- for (const key in editingFormula) {
- sheet.setFormula(
- editingFormula[key].row,
- editingFormula[key].col,
- editingFormula[key].data
- );
- }
- });
- };
复制代码
|