这个脚本在一个文档中工作,但在另一个文档中不起作用。我已经测试过修改选项卡名,使用数组和一堆if语句,真的不知道该去哪里。
最后,我要做的就是在文档中的每个选项卡上添加一行,减去以下几行:
function insertRow() {
// Retrieve the spreadsheet
const ss = SpreadsheetApp.getActiveSpreadsheet();
var allsheets = ss.getSheets();
var exclude = ["Sheet2", "Sheet5"];
for(var s in allsheets){
var sheet = allsheets[s];
// Stop iteration execution if the condition is meet.
if(exclude.indexOf(sheet.getName())==-1) continue;
sheets[i].insertRowBefore(row);
}
}发布于 2022-10-18 23:34:15
在第30行上方插入一行
function insertRowBefore30() {
const ss = SpreadsheetApp.getActive();
const shts = ss.getSheets();
var exclude = ["Sheet2", "Sheet5"];
shts.filter(sh => !~exlude.indexOf(sh.getName())).forEach(sh => sh.insertRowBefore(30));
}发布于 2022-10-18 23:28:26
修改要点:
sheets[i].insertRowBefore(row);。sheets,i,row都没有读。Ultimately, all I want to do is add a row above row 30 on every tab in my document minus a few:,insertRowBefore可能是insertRowsBefore。当这些点反映在您的脚本中时,下面的修改如何?
发自:
sheets[i].insertRowBefore(row);至:
sheet.insertRowsBefore(1, 30);sheet.insertRowsAfter(sheet.getLastRow(), 30);。注意:
var exclude = ["Sheet2", "Sheet5"];中使用特定的工作表。在本例中,在I jwant to add a SINGLE row above row #30.. I was doing "30,1" and it wasn't working there either中,下面的修改如何?- Fromsheetsi.insertRowBefore(行);
- Toif (sheet.getMaxRows() >= 30) { sheet.insertRowBefore(30);}
- When the number of rows is less than 30, an error occurs. Please be careful about this.var exclude = ["Sheet2", "Sheet5"];,请将if(exclude.indexOf(sheet.getName())==-1) continue;修改为if (exclude.indexOf(sheet.getName()) != -1) continue;。参考资料:
https://stackoverflow.com/questions/74118389
复制相似问题