Google-Apps-Script

Google-Apps-Script

google-apps-script #google- apps-script Table of Contents About 1 Chapter 1: Getting started with google-apps-script 2 Remarks 2 Examples 2 Installation or Setup 2 Types of Scripts 3 Running/Debugging your script 3 Hello World 4 A deeper look at Google Apps Script 4 Chapter 2: Apps Script Web Apps 6 Remarks 6 Examples 6 Web App Form 6 Chapter 3: Client calls to Google apps-script 12 Introduction 12 Examples 12 This is an example of a client side call to a Google app-script 12 Chapter 4: Create a custom function for Google Sheets 13 Introduction 13 Examples 13 Standard gravity custom constant 13 Basic Example 14 Chapter 5: DriveApp 15 Examples 15 Create a new folder in a Google Drive root 15 Create new file in Google Drive of a certain Mime type 15 Create a new text file in Google Drive root folder 15 Create a new file in Google drive from a blob 15 Get all folders - put folders into a continuation token - then retrieve from token 16 Get all files - put them into a continuation token - then retrieve them 16 Add a folder to the root drive 17 Create a new text file and add it to the root folder 17 Get all Files in a Drive Folder 18 Chapter 6: DriveApp - getFileById(id) 20 Remarks 20 Examples 20 Get a file from Google Drive using the file ID 20 Chapter 7: DriveApp Service 21 Remarks 21 Examples 21 Create a new folder in Google root drive 21 Create new file in Google Drive of a certain Mime type 21 Create a new text file in Google root drive folder 21 Create a new file in Google Drive from a blob 22 Get all folders - put folders into a continuation token - then retrieve from token 22 Get all files - put them into a continuation token - then retrieve them 23 Chapter 8: DriveApp Service - Files by type and search string 24 Parameters 24 Examples 24 Get files by file type with matching string in file name 24 Chapter 9: Firebase and AppScript : Introduction 26 Introduction 26 Examples 26 Connecting to a Firebase project in GAS and transferring data from Google Spreadsheet to F 26 Install Firebase resource in the the AppScript 26 Now let's take an example for reading and writing data from Firebase. 28 How to find the firebaseURL and the secret key? 29 Now you have inserted the firebaseURL and the secret key. Now you are all set to go. Click 30 Some more functions to implement read and write. 30 1. To write a simple data to test whether connection is working or not. 30 2. To read all the Data 30 3. To read a specific record 30 4. To update a specific record. 31 Chapter 10: GmailApp 32 Remarks 32 Examples 32 Get CSV file attached to a mail 32 Chapter 11: Google sheets MailApp 33 Introduction 33 Examples 33 A basic MailApp Example 33 Access data from sheet 33 Use Sheet data to send email 34 Sending HTML content in mail 36 Chapter 12: Google Web App Script To Auto Download From Google Drive 39 Introduction 39 Remarks 39 Examples 39 forms.html 39 code.gs 40 How it works 41 Chapter 13: Spreadsheet Add Menu 43 Syntax 43 Parameters 43 Remarks 43 Examples 43 Create a new menu 43 Create Custom Menu 44 Chapter 14: Spreadsheet Service 45 Remarks 45 Examples 45 Sheet 45 Copy a value from one sheet to current sheet 46 Get the last row in a single column 46 Inserting Arrays as Rows 47 Chapter 15: SpreadsheetApp Active Sheet 48 Remarks 48 Examples 48 getActive() - Get active spreadsheet 48 Credits 49 About You can share this PDF with anyone you feel could benefit from it, downloaded the latest version from: google-apps-script It is an unofficial and free google-apps-script ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow. It is neither affiliated with Stack Overflow nor official google-apps- script. The content is released under Creative Commons BY-SA, and the list of contributors to each chapter are provided in the credits section at the end of this book. Images may be copyright of their respective owners unless otherwise specified. All trademarks and registered trademarks are the property of their respective company owners. Use the content presented in this book at your own risk; it is not guaranteed to be correct nor accurate, please send your feedback and corrections to [email protected] https://riptutorial.com/ 1 Chapter 1: Getting started with google-apps- script Remarks The official overview for Google Apps Script is published at http://www.google.com/script/start, from there Google Apps Script is a JavaScript cloud scripting language that provides easy ways to automate tasks across Google products and third party services and build web applications. From https://developers.google.com/apps-script/guides/services/#basic_javascript_features Apps Script is based on JavaScript 1.6, plus a few features from 1.7 and 1.8. Many basic JavaScript features are thus available in addition to the built-in and advanced Google services: you can use common objects like Array, Date, RegExp, and so forth, as well as the Math and Object global objects. However, because Apps Script code runs on Google's servers (not client-side, except for HTML-service pages), browser- based features like DOM manipulation or the Window API are not available. Examples Installation or Setup Google Apps Script does not require setup or installation. The only requirement is a Google Account. A Gmail account works as well as a Google Apps for Work/Education/Government account. You can create a new Google account by going to accounts.google.com Start your first script by going to script.google.com. You can also access Google Apps Script under the tools -> Script editor... of many Google Apps i.e Docs, Sheets, Forms etc. Google Apps Script can also be added directly to your Google Drive with the Connect more apps.. feature. Official documentation can be found at developers.google.com/apps-script/. For app-scripts to run they must contain a code.gs file. The code.gs file must contain a function named doGet (standalone scripts) or an onOpen function (addon scripts). The quick starts in the documentation contain examples. If an api is turned on in the app-script it must also be turned on in the developers-console. However, the developers console contains api's that can be turned on but do not appear in the app-script interface. For example, Marketplace SDK needs to be turned on in the developers console before the app can be published to the Google play store or to a G suite domain wide deployment. https://riptutorial.com/ 2 For Google apps for education/work/government there are settings in the domain admin console that can be adjusted to allow or disallow app-scripts to run. Types of Scripts Google App scripts are of three types. • Standalone • Bound to Google Apps • Web Apps Standalone script Standalone scripts are not bound to any Google apps i.e Docs, Sheets or Forms etc. Standalone script can either be created by visiting script.google.com or by connecting Google app script with Google drive. Standalone script can be used to program Google apps independently, can be used as a Web App or can be set up to run automatically from an installable trigger. See the documentation for standalone script. Bound to Google Apps Script bound to Google Apps also known as container-bound script; unlike standalone scripts, are bound to Google apps i.e Google Docs or Google Sheets etc. Container bound script can be created by selecting tools> Script editor from Google App. Some features like dialogs, prompts, menus and sidebar are only provided by container-bound scripts. Furthermore, container-bound script is used to create Google Add-ons. See the documentation for container-bound scripts. Web Apps Google App Script can be used as web app as they can be accessed by browser. Web App can provide user interface on the browser and can make use of google apps i.e docs, sheets etc. Both standalone scripts and scripts bound to Google Apps can be turned into web apps. For any script to work as a web app, script has to meet two requirements: • include a doGet() or doPost() function. • The function returns an HTML service HtmlOutput object or a Content service TextOutput object. Inshort, doGet() and doPost() functions works like http get and post request handlers respectively. For more details on Web Apps, see the official documentation. Running/Debugging your script Try to run your code from the tool bar as shown below : https://riptutorial.com/ 3 In your code, if you have more than one function then, before running it you should mention the function you want to run with. For example : Alternatively, you can press ctrl + r from your keyboard to run the code. It will save the code first, if not saved, and then run it. But, for that to work, you must have selected the function, as seen in the image above. Also, if your script is called by some external activities, still you will be able to see logs by clicking view->logs if you are logging anything after the code is executed. Hello World We are going to say Hello as a message box. function helloWorld() { Browser.msgBox("Hello World"); } To execute the script, either click ▶ or select the menu item Run -> helloWorld A deeper look at Google Apps Script Google Apps Script is a JavaScript based platform-as-a-service primarily used to automate and extend Google Apps.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    55 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us