我在Google脚本方面还很年轻。我想在一个Google电子表格中使用多个Google日历。调试器说一切都正确,但是在我的电子表格上我看不到任何结果。
那是我写的:
function Calendar(){
var now=new Date();
var startpoint=new Date(now.getTime()-60*60*24*1000);
var endpoint=new Date(now.getTime()+60*60*24*100*1000);
var event1=CalendarApp.getCalendarById("df3r8epp4rpgc49eq4jmm2vot0@group.calendar.google.com").getEvents(startpoint, endpoint);
var event2=CalendarApp.getCalendarById("jie49v8l2vdhmrigruo587doss@group.calendar.google.com").getEvents(startpoint, endpoint);
var ss=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Kalender");
ss.clear();
for (var i,o=0;i<event1.length;i++) {
ss.getRange(i,o+1,1 ).setValues((event1[i])(event2[o].getTitel()));
答案 0 :(得分:1)
这应该有效。
function addEventTitles() {
var now = new Date();
var startpoint = new Date(now.getTime() - 60 * 60 * 24 * 1000);
var endpoint = new Date(now.getTime() + 60 * 60 * 24 * 100 * 1000);
var cal1 = CalendarApp.getCalendarById('df3r8epp4rpgc49eq4jmm2vot0@group.calendar.google.com');
var cal2 = CalendarApp.getCalendarById('jie49v8l2vdhmrigruo587doss@group.calendar.google.com');
var events1 = cal1.getEvents(startpoint, endpoint);
var events2 = cal2.getEvents(startpoint, endpoint);
var allEvents = events1.concat(events2);
// Put all the events into one array so we can loop through them
var sheet = SpreadsheetApp.getActive().getSheetByName('Kalender');
sheet.clear();
var eventTitles = [];
// Create an empty array we can add the titles to
for (var i = 0; i < allEvents.length; i++) {
eventTitles.push([allEvents[i].getTitle()]);
// Add each event title to the eventTitles array as an array (that's why it's surrounded by square brackets)
// Titles are added as an array due to Google's 2d array useage for row and column representation
}
sheet.getRange(1, 1, eventTitles.length, 1).setValues(eventTitles);
}