I did find this useful set of examples when I was flailing around Maintaing a Google Calendar from a Spreadsheet, Reprise.
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {name: "MakeEvent", functionName: "getEventFromSpreadSheet"} ];
sheet.addMenu("Events", menuEntries);
}
function getEventFromSpreadSheet () {
var range = SpreadsheetApp.getActiveRange();
var vals = range.getValues();
var Title = vals[0];
var Description = vals[1];
var Summary = vals[2];
var StartTime = vals[3];
var EndTime = vals[4];
var Location = vals[5];
var Guests = vals[6];
var GuestsStatus = vals[7];
var Invites = vals[8];
var Options = {description: Description,
guests: Guests,
location: Location,
sendInvites: Invites
};
makeEvent(Title, StartTime, EndTime, Options);
}
function makeEvent(Title, StartTime, EndTime, Options) {
var cal = CalendarApp.getDefaultCalendar();
cal.createEvent(Title, new Date(StartTime), new Date(EndTime), {location:'blah loc'}, {description: 'blah desc'});
}
W00t the fixes just clicked. Given my comments below here is the fixed code:
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {name: "MakeEvent", functionName: "getEventFromSpreadSheet"} ];
sheet.addMenu("Events", menuEntries);
}
function getEventFromSpreadSheet () {
var range = SpreadsheetApp.getActiveRange();
var vals = range.getValues();
var Title = vals[0][0];
var Description = vals[0][1];
var Summary = vals[0][2];
var StartTime = vals[0][3];
var EndTime = vals[0][4];
var Location = vals[0][5];
var Guests = vals[0][6];
var GuestsStatus = vals[0][7];
var Invites = vals[0][8];
var Options = {description: Description,
guests: Guests,
location: Location,
sendInvites: Invites
};
makeEvent(Title, StartTime, EndTime, Options);
}
function makeEvent(Title, StartTime, EndTime, Options) {
var cal = CalendarApp.getDefaultCalendar();
cal.createEvent(Title, new Date(StartTime), new Date(EndTime), Options);
}
And here is the CSV of the spreadsheet I tested with:
Title,Description,Summary,StartTime,EndTime,Location,Guests,GuestsStatus
MyTest,MyTest Description,MyTest Summary,9/22/2010 10:00:00,9/22/2010 11:00:00,Home Test,0000@noemail.gmail.com,yes
MyTest1,MyTest Description,MyTest Summary,10/22/2010 0:00:00,10/22/2010 0:00:00,Home Test,0000@noemail.gmail.com,yes
2 comments:
A range is a 2 dimensional structure. I left off one of the vals[0][1] portion. One issues fixed.
I was messing around with some of the various ways people formatted the Options portion. It's just a single Object, and needs to be specified properly.
Post a Comment