{"id":52636,"date":"2025-03-12T14:00:00","date_gmt":"2025-03-12T13:00:00","guid":{"rendered":"https:\/\/blog.sheetgo.com\/?p=52636"},"modified":"2025-08-20T21:48:29","modified_gmt":"2025-08-20T19:48:29","slug":"extrair-o-calendario-do-google-usando-o-script-de-aplicativos","status":"publish","type":"post","link":"https:\/\/www.sheetgo.com\/pt\/blog\/google-sheets-formulas\/pull-google-calendar-using-apps-script\/","title":{"rendered":"Extrair dados do Google Agenda para o Planilhas Google usando o Apps Script"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;4.27.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221; da_is_popup=&#8221;off&#8221; da_exit_intent=&#8221;off&#8221; da_has_close=&#8221;on&#8221; da_alt_close=&#8221;off&#8221; da_dark_close=&#8221;off&#8221; da_not_modal=&#8221;on&#8221; da_is_singular=&#8221;off&#8221; da_with_loader=&#8221;off&#8221; da_has_shadow=&#8221;on&#8221; da_disable_devices=&#8221;off|off|off&#8221;][et_pb_row _builder_version=&#8221;4.27.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;4.27.2&#8243; _module_preset=&#8221;default&#8221; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221;][et_pb_text _builder_version=&#8221;4.27.4&#8243; _module_preset=&#8221;default&#8221; hover_enabled=&#8221;0&#8243; global_colors_info=&#8221;{}&#8221; theme_builder_area=&#8221;post_content&#8221; sticky_enabled=&#8221;0&#8243;]<\/p>\n<blockquote>\n<p><strong>This post was originally published in our community forum. <\/strong><\/p>\n<\/blockquote>\n<p><strong>Objective :<\/strong><span>\u00a0<\/span>This guide demonstrates how to use Google Apps Script to pull data from Google Calendar and display them in a Google Sheet. This process allows you to automate the retrieval of calendar events and manage them directly within a spreadsheet.<\/p>\n<p><strong>Create a New Google Sheet:<\/strong><span>\u00a0<\/span>Open Google Sheets and create a new spreadsheet or open an existing one where you want the calendar data to be displayed.<\/p>\n<p><strong>Open Apps Script:<\/strong><span>\u00a0<\/span>In your Google Sheet, click on<span>\u00a0<\/span><code>Extensions<\/code><span>\u00a0<\/span>&gt;<span>\u00a0<\/span><code>Apps Script<\/code>.<\/p>\n<p><strong>Insert the Script:<\/strong><span>\u00a0<\/span>In your Apps Script project, you\u2019ll have two files:<span>\u00a0<\/span><code>Code.gs<\/code><span>\u00a0<\/span>and<span>\u00a0<\/span><code>props.gs<\/code>. Delete any existing code in the script editor and replace it with the code snippet provided below. Copy the provided code snippet for<span>\u00a0<\/span><code>Code.gs<\/code><span>\u00a0<\/span>and<span>\u00a0<\/span><code>props.gs<\/code><span>\u00a0<\/span>into their respective files.<\/p>\n<p><strong><code>props.gs<\/code><\/strong><\/p>\n<pre><code data-highlighted=\"yes\" class=\"hljs language-csharp\"><span class=\"hljs-keyword\">const<\/span> emailIds = [\n\u00a0 <span class=\"hljs-string\">'' \/\/ Include here the email address<\/span>\n];<\/code><\/pre>\n<p><strong><code>Code.gs<\/code><\/strong><\/p>\n<pre><code data-highlighted=\"yes\" class=\"hljs language-csharp\"><span class=\"hljs-function\">function <span class=\"hljs-title\">fetchCalendarData<\/span>()<\/span> {\n\n  <span class=\"hljs-comment\">\/\/ Get the active sheet<\/span>\n  <span class=\"hljs-keyword\">const<\/span> sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();\n  sheet.clear();  <span class=\"hljs-comment\">\/\/ Clear any previous content<\/span>\n\n  sheet.appendRow([<span class=\"hljs-string\">\"Meeting ID\"<\/span>, <span class=\"hljs-string\">\"Name\"<\/span>, <span class=\"hljs-string\">\"Attendees\"<\/span>, <span class=\"hljs-string\">\"Duration\"<\/span>, <span class=\"hljs-string\">\"Video Link\"<\/span>]);     <span class=\"hljs-comment\">\/\/ Set headers<\/span>\n\n  <span class=\"hljs-comment\">\/\/ Loop through each email ID<\/span>\n  emailIds.forEach(email =&gt; {\n    <span class=\"hljs-keyword\">const<\/span> events = CalendarApp.getCalendarById(email).getEvents(<span class=\"hljs-keyword\">new<\/span> Date(<span class=\"hljs-string\">'start_date'<\/span>), <span class=\"hljs-keyword\">new<\/span> Date()); \n    <span class=\"hljs-comment\">\/\/ Loop through events and write them to the sheet<\/span>\n    events.forEach(<span class=\"hljs-keyword\">event<\/span> =&gt; {\n      <span class=\"hljs-keyword\">const<\/span> eventId = <span class=\"hljs-keyword\">event<\/span>.getId();\n      <span class=\"hljs-keyword\">const<\/span> eventName = <span class=\"hljs-keyword\">event<\/span>.getTitle();\n      <span class=\"hljs-keyword\">const<\/span> attendees = <span class=\"hljs-keyword\">event<\/span>.getGuestList().map(guest =&gt; guest.getEmail()).<span class=\"hljs-keyword\">join<\/span>(<span class=\"hljs-string\">', '<\/span>);\n      <span class=\"hljs-keyword\">const<\/span> duration = (<span class=\"hljs-keyword\">event<\/span>.getEndTime() - <span class=\"hljs-keyword\">event<\/span>.getStartTime()) \/ (<span class=\"hljs-number\">1000<\/span> * <span class=\"hljs-number\">60<\/span>); \n      <span class=\"hljs-keyword\">let<\/span> videoLink = <span class=\"hljs-string\">\"\"<\/span>;\n      <span class=\"hljs-keyword\">const<\/span> description = <span class=\"hljs-keyword\">event<\/span>.getDescription();\n      <span class=\"hljs-keyword\">if<\/span> (description) {\n        <span class=\"hljs-keyword\">const<\/span> meetLinkRegex = \/https:\\\/\\\/calendly\\.com\\\/events\\\/[\\w-]+\\\/google_meet\/i; <span class=\"hljs-comment\">\/\/ Regex to match Video link<\/span>\n        <span class=\"hljs-keyword\">const<\/span> match = description.match(meetLinkRegex);\n        <span class=\"hljs-keyword\">if<\/span> (match) {\n          videoLink = match[<span class=\"hljs-number\">0<\/span>]; \n        }\n      } \n      sheet.appendRow([eventId, eventName, attendees, duration, videoLink]);\n    });\n  });\n\n  Logger.log(<span class=\"hljs-string\">\"Calendar data has been fetched and updated in the sheet.\"<\/span>);\n}<\/code><\/pre>\n<p><strong>Update Email IDs:<\/strong><span>\u00a0<\/span>In<span>\u00a0<\/span><code>props.gs<\/code>, add the email ID of the calendar you want to pull data from. You can adjust the date range by modifying the<span>\u00a0<\/span><code>start_date<\/code><span>\u00a0<\/span>in the<span>\u00a0<\/span><code>code.gs<\/code><span>\u00a0<\/span>file.<\/p>\n<p><strong>Execute the script:<\/strong><span>\u00a0<\/span>You might be prompted to authorize the script to access your calendar and spreadsheet. After running the script, your Google Sheet should populate with the event data from the specified Google Calendar.<\/p>\n<p>By following these steps, you can easily automate the process of pulling calendar data into your Google Sheets, making it easier to manage and analyze your schedule.<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post was originally published in our community forum. Objective :\u00a0This guide demonstrates how to use Google Apps Script to pull data from Google Calendar and display them in a Google Sheet. This process allows you to automate the retrieval of calendar events and manage them directly within a spreadsheet. Create a New Google Sheet:\u00a0Open [&hellip;]<\/p>\n","protected":false},"author":48,"featured_media":44470,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[54],"tags":[],"class_list":["post-52636","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-google-sheets-formulas"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/posts\/52636","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/comments?post=52636"}],"version-history":[{"count":0,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/posts\/52636\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/media\/44470"}],"wp:attachment":[{"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/media?parent=52636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/categories?post=52636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sheetgo.com\/pt\/wp-json\/wp\/v2\/tags?post=52636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}