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

Google Apps Script中CalendarApp.createCalendar选项异常求助

问题分析与修复方案

核心问题1:参数名错误

Google Apps Script 的 CalendarApp.createCalendar() 方法中,用于设置日历描述的高级参数是 description,而非你代码里写的 summary——这就是日志里描述为空的直接原因。

核心问题2:变量名拼写/未定义错误

  • 你定义的变量是 calName,但创建日历名称时误用了未定义的 nomCal,会导致名称异常(日志里的正常名称可能是你测试时临时修正过,但代码里的拼写错误必须修复)。
  • 字符串里的 ${district} 是未定义变量,推测你想使用的是已有的 calName 变量。

修复后的代码

function createCalendar() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Détail");
  SpreadsheetApp.setActiveSheet(sheet);
  
  const calName = sheet.getRange(3, 1).getValue();
  const year = sheet.getRange(3, 2).getValue();
  const color = sheet.getRange(3, 4).getBackground();
  const calendar = CalendarApp.createCalendar(
    `District ${calName}`, 
    {
      description: `Here you'll find all the important events in the ${calName} for the year ${year}`,
      timeZone: "Europe/Paris",
      color: color
    }
  );
  
  console.log('created calendar "%s", with ID : "%s", description: "%s" and color: "%s".',
    calendar.getName(), calendar.getId(), calendar.getDescription(), calendar.getColor());
}

额外修正:原字符串里的 importants 拼写错误,已改为 important。

内容的提问来源于stack exchange,提问作者mthgn

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 15:15:32