Sytax error: Missing ), but I don't see it. My quotation marks don't seem to be the problem either

Sytax error: Missing ), but I don't see it. My quotation marks don't seem to be the problem either

我一直在研究这个应用程序脚本,试图自动化来自 Google sheet 的数据,以在 Google 日历上创建事件。我试过将引号从单引号改为双引号,然后再改回来。我一遍又一遍地检查了我的 () 。我看不到我所做的导致语法错误的事情。如果你能看到它,请告诉我。这让我抓狂。

function AutomateCalendarEvent() {
  let sheet = SpreadsheetApp.getActiveSheet();
  let pqCalendar = CalendarApp.getCalendarById("zyxwvutsrqp");  
  let reservation = sheet.getRange("C2:E1105").getValues();
  reservation.splice(0, 1);
  let rows = sheet.getDataRange().getValues();
  rows.forEach(function (row, index)  {
    if (index === 0) return;
    if (row[C3]) return;
    
  pqCalendar.createAllDayEvent("Last Name"C2:C, "Arrival Date"D2:D, "Departure Date"E2:E);
    
   })
}

看看我的评论

function AutomateCalendarEvent() {
  let sheet = SpreadsheetApp.getActiveSheet();
  let pqCalendar = CalendarApp.getCalendarById("zyxwvutsrqp");  
  let reservation = sheet.getRange("C2:E1105").getValues();
  reservation.splice(0, 1);
  let rows = sheet.getDataRange().getValues();
  rows.forEach(function (row, index)  {
    if (index === 0) return;
    if (row[C3]) return;//C3 should be an index between 0 and 2
    
  pqCalendar.createAllDayEvent("Last Name"C2:C, "Arrival Date"D2:D, "Departure Date"E2:E);//parameters should be a string followed by two dates
    //this is not the way insert parameters into above command.  Ranges do not return values
   })
}

假设你的数据如下

尝试(为防止重复,事件 ID 存储在实例的 AI 列中)

function AutomateCalendarEvent() {
  let sheet = SpreadsheetApp.getActiveSheet();
  let swCalendar = CalendarApp.getCalendarById("***********@gmail.com");
  let rows = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()).getValues();
  rows.filter(row => row[2] != '').forEach(function (row, index) {
    if (index === 0) return;
    if (row[34] == '') { // AI
      try {
        sheet.getRange('AI' + (+index + 1)).setValue(swCalendar.createAllDayEvent(row[2], row[3], row[4]).getId())
      } catch (e) { console.log(e) }
    }
  })
}

参考

createAllDayEvent(title, startDate, endDate, {options})