您好,原生上没有相关的配置,我这边通过事件实现了您的这个需求,请参考:
- 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();
- let sheet = spread.getActiveSheet();
- let formulaArray;
- sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, (sender, args) => {
- console.log(args);
- let { cellRange } = args;
- formulaArray = traverseCellRangeIfFormula(
- sheet,
- cellRange.row,
- cellRange.col,
- cellRange.rowCount,
- cellRange.colCount
- );
- });
- sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, (sender, args) => {
- console.log(formulaArray);
- for (const key in formulaArray) {
- sheet.setFormula(
- formulaArray[key].row,
- formulaArray[key].col,
- formulaArray[key].formula
- );
- }
- });
- };
- function traverseCellRangeIfFormula(sheet, row, col, rowCount, colCount) {
- let result = {};
- for (let i = row; i < row + rowCount; i++) {
- for (let j = col; j < col + colCount; j++) {
- let cell = sheet.getCell(i, j);
- if (cell.formula()) {
- let key = `${i},${j}`;
- if (result[key]) {
- result[key].formula = cell.formula();
- } else {
- result[key] = {
- row: i,
- col: j,
- formula: cell.formula(),
- };
- }
- }
- }
- }
- return result;
- }
复制代码
|