我需要更改什么才能使该脚本将公式(从第 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/