Google Apps Script导出CSV报错TypeError: curDate is not a function求助
问题排查与修复:Google Apps Script导出CSV时的TypeError错误
错误根源
报错TypeError: curDate is not a function是因为代码中错误地将字符串变量当作函数调用:
原代码里curDate()的写法有误,curDate是通过Utilities.formatDate生成的字符串变量,并非函数,不能加括号执行。
错误代码定位
问题出在这一行:
blob.setName('Daily Shipments Import ' + curDate() + '.csv');
修复后的完整代码
将上述错误行中的curDate()改为curDate即可,修复后的完整函数代码如下:
function exportSheetAsCSV() { function getFileAsBlob(exportUrl) { let response = UrlFetchApp.fetch(exportUrl, { muteHttpExceptions: true, headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken(), }, }); return response.getBlob(); } let blob = getFileAsBlob("https://docs.google.com/spreadsheets/d/sheetURL/export?format=csv"); var curDate = Utilities.formatDate(new Date(), "GMT","MM-dd-yyyy"); // 修复:移除curDate后的括号,直接使用变量值 blob.setName('Daily Shipments Import ' + curDate + '.csv'); var foID = 'folderURL'; var folder = DriveApp.getFolderById(foID); folder.createFile(blob); }
触发器说明
你添加的.nearMinute()方法配置没有问题,触发器执行时间设置正确,本次报错与触发器调整无关,仅为函数内部变量调用错误导致。
内容的提问来源于stack exchange,提问作者Jose Jimenez
相关产品推荐
相关产品推荐

