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
相关产品推荐
相关产品推荐

