{"id":666,"date":"2025-03-31T13:19:27","date_gmt":"2025-03-31T13:19:27","guid":{"rendered":"http:\/\/kevinmichaelcoy.com\/blog\/?p=666"},"modified":"2025-03-31T13:23:08","modified_gmt":"2025-03-31T13:23:08","slug":"syncing-data-from-google-sheets-to-events-in-google-calendar","status":"publish","type":"post","link":"http:\/\/kevinmichaelcoy.com\/blog\/2025\/03\/31\/syncing-data-from-google-sheets-to-events-in-google-calendar\/","title":{"rendered":"Syncing Data from Google Sheets to Events in Google Calendar"},"content":{"rendered":"\n<p>From Google Sheets you can add an &#8220;App Script&#8221; from the &#8220;Extensions&#8221; menu.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"248\" src=\"https:\/\/kevinmichaelcoy.com\/blog\/wp-content\/uploads\/2025\/03\/image-1024x248.png\" alt=\"\" class=\"wp-image-667\" srcset=\"http:\/\/kevinmichaelcoy.com\/blog\/wp-content\/uploads\/2025\/03\/image-1024x248.png 1024w, http:\/\/kevinmichaelcoy.com\/blog\/wp-content\/uploads\/2025\/03\/image-300x73.png 300w, http:\/\/kevinmichaelcoy.com\/blog\/wp-content\/uploads\/2025\/03\/image-768x186.png 768w, http:\/\/kevinmichaelcoy.com\/blog\/wp-content\/uploads\/2025\/03\/image-150x36.png 150w, http:\/\/kevinmichaelcoy.com\/blog\/wp-content\/uploads\/2025\/03\/image.png 1057w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This will allow you to do a few things, such as code and test an App Script. Here we most importantly need a way to sync some rows from a sheet that we can consider as events in Google Calendar. <\/p>\n\n\n\n<p>I was following this link, but it is like a bunch of clickbait to go load a bunch of other blog posts and videos (for ad revenue I&#8217;m sure). Not to mention it is incomplete and missing important details in my opinion.<\/p>\n\n\n\n<p>TL;DR, here are three functions you can add that will allow you to trigger a sync from the Google Sheet document to Google Calendar. It will take care of looping and deleting existing events from that day to prevent duplications and is actually fully functioning.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\/\/ https:\/\/developers.google.com\/apps-script\/guides\/menus\n\/\/ https:\/\/workspace.google.com\/blog\/productivity-collaboration\/g-suite-pro-tip-how-to-automatically-add-a-schedule-from-google-sheets-into-calendar\n\/\/ https:\/\/medium.com\/@dontmesswithjo\/coding-basics-for-loops-90dca2873c70\n\/\/ https:\/\/medium.com\/@dontmesswithjo\/custom-menus-94d8e4325b0d\nfunction onOpen() {\n  var ui = SpreadsheetApp.getUi();\n  \/\/ Or DocumentApp, SlidesApp or FormApp.\n  ui.createMenu('Sync to Calendar')\n      .addItem('Schedule Reservations', 'scheduleReservations')\n      .addToUi();\n}\n\nfunction scheduleReservations() {\n  SpreadsheetApp.getUi() \/\/ Or DocumentApp, SlidesApp or FormApp.\n     .alert('You clicked the first menu item!');\n  syncReservations();\n}\n\nfunction syncReservations() {\n  var spreadsheet = SpreadsheetApp.getActiveSheet();\n  var calendarId = \"foobar@group.calendar.google.com\";\n\n  var eventCal = CalendarApp.getCalendarById(calendarId);\n\n  var reservations = spreadsheet.getRange(\"A18:D30\").getValues();\n\n  for (x=0; x&lt;reservations.length; x++) {\n    var reservation = reservations[x];\n    \n    var startTime = reservation[2];\n    var endTime = reservation[3];\n    var title = reservation[0] + \" @ \" + reservation[1];\n\n    if(title.trim().length > 2) {\n      \/\/ clean up any existing events from the day first\n      eventCal.getEventsForDay(new Date(startTime)).forEach(function(e){\n        Logger.log(e.getTitle());\n        e.deleteEvent();\n      })\n\n      \/\/ create new events\n      Logger.log(\"Creating event with title [\" + title + \"]\");\n      eventCal.createEvent(title, new Date(startTime), new Date(endTime));\n    }\n  }\n}\n<\/code><\/pre>\n\n\n\n<p>Just in case you care,<\/p>\n\n\n\n<ul><li>Column A &#8211; contains a name<\/li><li>Column B &#8211; contains a title \/ location<\/li><li>Column C &#8211; Start day <\/li><li>Column D &#8211; End day<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>From Google Sheets you can add an &#8220;App Script&#8221; from the &#8220;Extensions&#8221; menu. This will allow you to do a few things, such as code and test an App Script. Here we most importantly need a way to sync some rows from a sheet that we can consider as events&#8230;<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"http:\/\/kevinmichaelcoy.com\/blog\/2025\/03\/31\/syncing-data-from-google-sheets-to-events-in-google-calendar\/\">Continue reading<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,3],"tags":[],"_links":{"self":[{"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/posts\/666"}],"collection":[{"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/comments?post=666"}],"version-history":[{"count":5,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/posts\/666\/revisions"}],"predecessor-version":[{"id":673,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/posts\/666\/revisions\/673"}],"wp:attachment":[{"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/media?parent=666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/categories?post=666"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/tags?post=666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}