This repository contains comprehensive and enhanced examples of using various Google Apps Script libraries. Each folder now features improved scripts demonstrating practical, real-world usage, complete with detailed explanations, modern JavaScript practices, and robust error handling.
This repository has undergone a significant overhaul to provide more valuable and runnable examples:
- Workflow-Oriented Examples: Many directories (e.g.,
SpreadsheetApp,DriveApp,DocumentApp,FormApp,CalendarApp) now feature single, comprehensive workflow scripts. These scripts demonstrate end-to-end processes (e.g., building a full report, managing calendar events, processing email attachments) that are self-contained and require no manual setup or hardcoded IDs. - Enhanced Individual Scripts: For services where a single workflow wasn't appropriate (e.g.,
GmailApp,UrlFetchApp,ScriptApp), individual scripts have been significantly improved with:- Detailed JSDoc comments for better understanding.
- Modern JavaScript syntax (ES6+).
- Robust error handling (
try...catch). - More practical and illustrative use cases.
- Clearer logging and verification steps.
- Consolidated Demonstrations: Services like
LoggerandPropertiesServicenow feature single, well-documented scripts that comprehensively demonstrate all their core functionalities and different scopes. - Clearer
HtmlServiceExamples: TheHtmlServiceexamples have been refactored into distinct, runnable demonstrations covering web apps, sidebars with data exchange, styled modal dialogs, and embedded charts.
| 🔧 Library | 📝 Description | 🔗 Examples |
|---|---|---|
| 📂 DriveApp | Access and manage Google Drive. | 🌐 View Examples |
| 📊 SpreadsheetApp | Manage and interact with Google Sheets. | 🌐 View Examples |
| 📅 CalendarApp | Interact with Google Calendar. | 🌐 View Examples |
| ✉️ GmailApp | Read and send emails with Gmail. | 🌐 View Examples |
| 🌐 UrlFetchApp | Fetch data from external APIs. | 🌐 View Examples |
| 🛠️ Utilities | Useful helper methods for data manipulation. | 🌐 View Examples |
| 📋 FormApp | Manage and automate Google Forms. | 🌐 View Examples |
| ⏰ ScriptApp | Manage triggers, OAuth tokens, and project settings. | 🌐 View Examples |
| 📄 DocumentApp | Create and edit Google Docs programmatically. | 🌐 View Examples |
| 🎨 HtmlService | Build custom user interfaces using HTML, CSS, and JS. | 🌐 View Examples |
| 🪵 Logger | Log information for debugging purposes. | 🌐 View Examples |
| 🗄️ PropertiesService | Store and retrieve script settings and user data. | 🌐 View Examples |
-
Open Google Apps Script:
- Open a Google Workspace app (e.g., Google Sheets, Docs).
- Navigate to Extensions > Apps Script.
-
Copy the Code:
- Browse the examples in the desired library folder.
- Copy the code into the Apps Script editor.
- Important: For workflow examples, copy the entire
.gsfile. ForHtmlServiceexamples, copy both the.gsfile and the embedded HTML content (if applicable) into separate.htmlfiles in your Apps Script project, or directly into the.gsfile as shown in the examples.
-
Test and Execute:
Customize and run the code in your Google Workspace environment. Ensure you grant any necessary permissions when prompted.
Contributions are welcome! Whether it's fixing bugs, adding new examples, or improving documentation, feel free to submit a pull request. Please ensure all additions are well-documented and tested.