我试图在App脚本中运行循环,但脚本在第二次执行循环时停止。
Google Doc id来自Google工作表中的列表。我可以让它在没有循环的情况下工作,但是一旦工作表范围被更新,它就不会查看下一个id。有人能看到哪里出了问题吗?
function myFunction() {
var ss = SpreadsheetApp.openById('1LETEuEdYxyIxQtQgFWTwm3GgZWDAR5ehUUEIh_jN7zA');
var sheet = ss.getSheetByName('Sheet1');
var lr = sheet.getRange(2,5).getDataRegion(SpreadsheetApp.Dimension.ROWS).getLastRow();
for(var i=0; i<lr+1; i++) {
var id = sheet.getRange(i+2,5,1,1).getValue();
var doc = DocumentApp.getActiveDocument();
var docInside = DocumentApp.openById(id).getBody();
var text = docInside.getTables();
var table = text[3].getNumRows();
var val = text[3].getRow(2).getText();
var pasteArea = doc.editAsText();
pasteArea.appendText(val);
var text = docInside.getTables();
var loops = text[7].getNumRows();
for(var i=0; i<loops-5; j++) {
var val = text[7].getRow(j+5).getText();
var pasteArea = doc.editAsText();
pasteArea.appendText(val);
}
}
};发布于 2019-11-10 00:34:06
试试这个:
function myFunction() {
var ss=SpreadsheetApp.openById('1LETEuEdYxyIxQtQgFWTwm3GgZWDAR5ehUUEIh_jN7zA');
var sh=ss.getSheetByName('Sheet1');
var lr=sh.getRange(2,5).getDataRegion(SpreadsheetApp.Dimension.ROWS).getLastRow();
var vA=sh.getRange(2,5,lr-1,1).getValues();
var doc = DocumentApp.getActiveDocument();
for(var i=0;i<vA.length;i++) {
var docid=DocumentApp.openById(vA[i][0]);
var tA=docid.getBody().getTables();
doc.getBody().appendParagraph(tA[3].getRow(2).getText());
var rows=tA[7].getNumRows();
for(var j=0;j<rows-5;i++) {
doc.getBody().appendParagraph(tA[7].getRow(j+5).getText());
}
}
}https://stackoverflow.com/questions/58773538
复制相似问题