You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 04:17:27