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

在Google Apps Script中设置calendarID变量遇阻(表格同步GCal场景)

Fixing Your Google Apps Script Calendar ID Retrieval Issue

Let's break down the two key issues in your code and fix them right away:

1. Wrong Column Index for Cell G2

Google Apps Script uses 1-based indexing for columns in getRange(row, column). Since column A is 1, column G is actually the 7th column—not 6. Your current getRange(2,6) is targeting cell F2 instead of G2.

2. Incorrect Way to Call getValue()

You already stored the range object in the range variable, so you don't need to reference it through the sheet object again. sheet.range is invalid because the Sheet class doesn't have a property named range—this will throw a runtime error.


Corrected Code

var sheet = SpreadsheetApp.getActiveSheet();
// Target G2: row 2, column 7
var range = sheet.getRange(2, 7);
// Call getValue() directly on the range variable
var calendarId = range.getValue();

Quick Verification Tip

To double-check you're grabbing the right cell, you can add a log statement to confirm the value:

Logger.log("Calendar ID retrieved: " + calendarId);

Then check the logs via View > Logs in the Apps Script editor to ensure it matches the ID in G2.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:46:20