Google脚本日历更新

问题描述 投票:0回答:1

我有两张纸,其中一张是Sheet1(主纸),另一张是事件(为了避免重复而过多地跟踪事件)...我不知道我的代码没有提供输出是什么问题。任何帮助表示赞赏。

function create_event(){
     var sheet  = SpreadsheetApp.getActiveSpreadsheet()
     var tab = sheet.getSheetByName("events")
     var sheet1 = sheet.getSheetByName("Sheet1")
     var calendarId = sheet.getRange("H2").getValue()
     var eventCal = CalendarApp.getCalendarById(calendarId)
     var data = tab.getRange(2, 1, tab.getLastRow(), tab.getLastColumn()).getValues()   
     var sheet1data = sheet1.getRange(8, 1, sheet1.getLastRow(), sheet1.getLastColumn()).getValues()
       var row_num = 8
     for(i in data){
       for (j in sheet1data){
       if(data[i][3] == ""){
         //create event logic here
         var event = eventCal.createEvent(sheet1data[j][2], new Date(sheet1data[j][0]), new Date(sheet1data[j][1]), {description: sheet1data[j][3]});
         var event_id = event.getId();
         eventCal.createEvent(sheet1data[j][2], new Date(sheet1data[j][0]), new Date(sheet1data[j][1]), {description: sheet1data[j][3]});

         sheet1.getRange(row_num, 8, sheet1.getLastRow()-row_num+1, 1).setValue(event_id)

         data[i][0]=sheet1data[j][0]
         data[i][1]=sheet1data[j][1]
         data[i][2]=sheet1data[j][2];
         data[i][3]=sheet1data [j][3];
         data[i][4]=sheet1data[j][4];
         data[i][5]=sheet1data[j][7];

       }//endif

      if (sheet1data[j][4]!=data[i][5]){
        //update calendar here
         var aaa = eventCal.getEventSeriesById(event_id)
       aaa.deleteEventSeries();
        eventCal.createEvent(sheet1data[j][2], new Date(sheet1data[j][0]), new Date(sheet1data[j][1]), {description: sheet1data[j][3]});

        //update the events sheet

        data[i][0]=sheet1data[j][0]
         data[i][1]=sheet1data[j][1]
         data[i][2]=sheet1data[j][2];
            data[i][3]=sheet1data [j][3];
           data[i][4]=sheet1data[j][4]; 
           data[i][5]=sheet1data[j][7];
      }

       row_num++
          }//endforj
     }//endfori    

}//endfunc
google-apps-script google-sheets google-calendar-api
1个回答
0
投票

看看这个:

function loadSomeDataIntoSheet() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  sh.clearContents();
  SpreadsheetApp.flush();//force it to clear data now
  var data=[];
  var n=0;
  for(var i=0;i<10;i++) {
    data[i]=[];
    for(var j=0;j<10;j++) {
      data[i][j]=n++;
    }
  }
  SpreadsheetApp.getUi().alert('Got data in arrays but no data in spreadsheet yet');
  sh.getRange(1,1,data.length,data[0].length).setValues(data);  
  SpreadsheetApp.flush();//force data to appear now
  SpreadsheetApp.getUi().alert('Now you have data on the spreadsheet.');
}
© www.soinside.com 2019 - 2024. All rights reserved.