javascript - 如何使用 Google Apps 脚本将 Formulas() 设置为某个范围?

标签 javascript google-apps-script google-sheets

我需要更改什么才能使该脚本将公式(从第 2 行开始)设置为定义的范围? 下面的代码没有给我任何错误,但它根本没有设置公式。

  var lc = sheet.getLastColumn();
  var range = sheet.getRange(2, 1, 1, lc);
  var formulas = range.getFormulas();
  
  range.copyFormatToRange(sheet, 1, lc, 3, 3+response); //This pastes the format to the range, whose number of rows is defined depending on the # that the user inputs.

  var pasteTo = sheet.getRange(3, 1, response, lc);//Defines the range for setting formulas
  for (var a = 3; a < response; a++){
    pasteTo = sheet.getRange("A" + a,sheet.getLastColumn());
    pasteTo.setFormulas(formulas);
  }
  }
}

最佳答案

在数组中执行所有操作都要快得多

function kdkdkd() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet0');
  const osh = ss.getSheetByName('Sheet1');
  const fA = sh.getRange(2, 1, sh.getLastRow() - 1, sh.getLastColumn()).getFormulas();
  osh.getRange(row,col,fA.length,fA[0].length).setFormulas(fA);  
}

选择你想要的行和列

关于javascript - 如何使用 Google Apps 脚本将 Formulas() 设置为某个范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70416161/

相关文章:

javascript - 在本地保存 JSON 文件

javascript - 从 Promise.all 解构为对象

javascript - WebView选择导致软键盘暂时隐藏再回来

javascript - 为 'on form submit' 触发器指定表单

google-chrome - 如何在 Google Apps 脚本的警报/提示对话框中使用换行符?

google-apps-script - 不断收到抱歉,无法删除所有非卡住行

javascript - Google Spreadsheet——通过脚本获取共享权限

javascript - 计算 WiFi 带宽或 WiFi 信号强度

javascript - 计算 Google 表格脚本中的粗体单元格

javascript - 选择当前行中的列(Google Sheets 脚本)