无法检索下一个对象:迭代器已到达末尾



我正试图从共享谷歌磁盘中的电子表格中创建一个pdf,但我正试图找出生成pdf的障碍。问题就在这一行:

var driveFolder = DriveApp.getFoldersByName(folderName).next(); 

这是整个代码:

function createPDF() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Article 19");
var folderName=ss.getRangeByName("NumAff").getValue();
var fileName='Tableau 19.09_' + ss.getRangeByName("NumAff").getValue();
sheet.showSheet();
var gid = sheet.getSheetId();
const pdfOpts = '&top_margin=0.30&bottom_margin=0.30&left_margin=0.25&right_margin=0.25'
+'&size=LETTER' // paper size letter / You can use A4 or legal
+'&portrait=true' // orientation portal, use false for landscape
+'&fitw=true' // fit to page width false, to get the actual size
+'&sheetnames=false' // hide optional headers
+'&printtitle=false' //and footers
+'&pagenumbers=false' // hide page numbers 
+'&gridlines=false' //and gridlines
+'&horizontal_alignment=CENTER'
+'&vertical_alignment=CENTER'
+'&fzr=true' // do not repeat row headers (frozen rows) on each page
+'&attachment=false'
+'&gid='+gid;
var url = ss.getUrl().replace(/edit$/, '') + 'export?format=pdf' + pdfOpts // export as pdf / csv / xls / xlsx
var options = {headers: {'Authorization': 'Bearer ' +  ScriptApp.getOAuthToken()}}
var blobresponse = UrlFetchApp.fetch(url, options);
var blob=blobresponse.getBlob().setName(ss.getName() +".pdf" );
var driveFolder = DriveApp.getFoldersByName(folderName).next(); 
var file = driveFolder.createFile(blob);
file.setName(fileName);
}

希望有人能向我解释问题的来源。

在处理folderfile时,应该检查迭代器。

我认为folderName并没有达到预期效果。

var folders = DriveApp.getFoldersByName(folderName); 
if (folders.hasNext()) {
var driveFolder = folders.next();
}

参考:FolderIterator

相关内容

  • 没有找到相关文章

最新更新