Created
February 12, 2024 22:15
-
-
Save ScriptRaccoon/c198f08da3fa229d34c6fbcc0bf5c90b to your computer and use it in GitHub Desktop.
Google Apps Script to sync from Spreadsheet to Calendar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This script needs to be bound with a Google Spreadsheet. | |
It needs to have a header row of the form: title | start | end | description | |
The script then generates calendar entries for every row below. | |
For example, the sheet could have the following entries (displayed in csv format): | |
Title,Start,End,Description | |
Test 1,27.02.2024 11:00:00,27.02.2024 15:00:00,Hallo 1 | |
Test 2,28.02.2024 15:00:00,28.02.2024 17:30:00,Hallo 2 | |
Test 3,26.02.2024 13:00:00,26.02.2024 16:00:00,Hallo 3 | |
*/ | |
/** | |
* number of rows in the header | |
*/ | |
const offset = 1; | |
/** | |
* first sheet | |
*/ | |
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0] | |
/** | |
* Creates calendar entries for each row in the associated sheet | |
*/ | |
function create_calendar_entries_from_sheet() { | |
const rows = sheet.getSheetValues(1+offset,1,sheet.getLastRow()-offset,sheet.getLastColumn()); | |
for (const row of rows) { | |
const [title, start, end, description] = row; | |
try { | |
const event = CalendarApp.createEvent(title,start,end,{description}); | |
console.log(`Created event "${event.getTitle()}" (ID: ${event.getId()})`) | |
} catch(e) { | |
console.error("Could not create event:"); | |
console.error(e) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment