Learning Google Apps Script - Ramalingam Ganapathy - E-Book

Learning Google Apps Script E-Book

Ramalingam Ganapathy

0,0
34,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Customize and automate Google Applications using Apps Script

About This Book

  • Gain insight into customizing and automating Google applications with JavaScript
  • Create add-ons for Google Sheets, Docs, or Forms; automate your workflow; integrate with external APIs; and more.
  • A step-by-step guide to building real-world solutions

Who This Book Is For

Newbies to google apps script but having practical experience in Javascript.

What You Will Learn

  • Learn about the Google Apps script platform and work with scripts to develop Google apps
  • Create custom menus and dialogs
  • Parse and send emails
  • Generate Google calendar events
  • Build Translator and RSS reader applications
  • Develop interactive web pages
  • Design interactive web-forms
  • Form a workflow application

In Detail

Google Apps Script is a cloud-based scripting language based on JavaScript to customize and automate Google applications.

Apps Script makes it easy to create and publish add-ons in an online store for Google Sheets, Docs, and Forms.

It serves as one single platform to build, code, and ultimately share your App on the Web store.

This book begins by covering the basics of the Google application platform and goes on to empower you to automate most of the Google applications.

You will learn the concepts of creating a menu, sending mails, building interactive web pages, and implementing all these techniques to develop an interactive Web page as a form to submit sheets

You will be guided through all these tasks with plenty of screenshots and code snippets that will ensure your success in customizing and automating various Google applications

This guide is an invaluable tutorial for beginners who intend to develop the skills to automate and customize Google applications

Style and approach

An easy-to-follow yet comprehensive guide, filled with many code examples and screenshots illustrating various Google Apps scripts.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 168

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Learning Google Apps Script
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Introducing Google Apps Scripts
Google Applications
Google Apps Script
Visual Basic for Applications
The advantages of GAS over VBA
The limitations of GAS
Google Drive
Gmail
Google Calendar
Google Docs
Google Sheets
Google Apps services
Creating Google Sheets in Drive and sharing them with your friends and the public
Script projects
Creating standalone script projects
Creating new projects in Sheets
Creating a custom formula in Sheets
Google Forms
Creating Forms within Google Sheet
Some research
Summary
2. Creating Basic Elements
Creating a clickable button
Showing toast when a button is clicked
Creating a custom menu
Creating a sidebar
Creating an Add-ons menu
Creating a modal dialog
Creating a modeless dialog
Debugging your script
Summary
3. Parsing and Sending E-mails
Creating Gmail Contacts by script
Accessing Sheet, cell, range, and offset
Reading and writing the Sheet data
Building a Gmail Contact search application
Building the Gmail parser application
Properties service
Downloading Gmail attachments to Drive
Sending e-mails using the MailApp service
Sending an e-mail notification on Form submission
Creating triggers manually
Creating and deleting triggers by script
Forwarding e-mails if the specific keyword is found in the message body
Sending e-mail with attachments
Embedding inline images in an e-mail message
Building an e-mail merger application
Summary
4. Creating Interactive Forms
Creating Forms using script
Publishing the script as a web application
HtmlService
Creating a Form using HtmlService
Submitting form using Google script API method
Creating forms using add-ons CSS and jQuery libraries
Creating an e-voting application
Creating a ticket reservation application
Summary
5. Creating Google Calendar and Drive Applications
The CalendarApp class
Creating Calendar events from a simple description
Creating simple Calendar events
Creating events with options
Creating events from Sheets data
Creating events from an external CSV file's contents
Enabling advanced Google services
Listing all the Calendars
Listing Calendar events in Sheets
Syncing events from one Calendar to another Calendar
The DriveApp class
Creating customized PDF files
Creating a Drive file routing application
Creating a Drive file search application
Summary
6. Creating Feed Reader and Translator Applications
The UrlFetchApp class
Creating a Google search application
Creating a stock quote ticker application
Logging Bitcoin quotes
RSS and Atom feeds
Skeleton of a RSS feed document
Creating an RSS reader application
Skeleton of an Atom feed document
Creating an Atom feed reader application
Using optional parameters with the UrlFetchApp class
The LanguageApp class
Creating the language translator application
Creating a document reviewing and instant inline commenting application
Summary
7. Creating Interactive Webpages
Creating a web app to render Sheet data as HTML
Creating a web app to return JSON
Converting Sheet data as a PDF file
Sending an HTTP/HTTPS request with query string
Creating RSS feed using ContentService
Creating a file upload application
Creating an employee timesheet application
Summary
8. Building a Workflow Application
Order processing workflow – steps explained
Configuring Google Sheets
Creating the Order form
Enhancing the Order form
Creating the dispatch form
Dispatching the articles
Enabling the user to acknowledge the article delivery
Summary
9. More Tips and Tricks and Creating an Add-on
Overcoming the "script exceeded maximum execution time" error
Configuring your script project to use external libraries
Using JSDoc annotations
Using the OAuth open source library
Creating, testing, and publishing add-ons
Installing add-ons from Chrome Web Store
Creating custom add-ons
Testing your add-on
Creating an add-on that uses an OAuth2 external library
Other useful links
Summary
Index

Learning Google Apps Script

Learning Google Apps Script

Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: March 2016

Production reference: 1140316

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78588-251-7

www.packtpub.com

Credits

Author

Ramalingam Ganapathy

Reviewer

Serge Gabet

Commissioning Editor

Priya Singh

Acquisition Editors

Vinay Argekar

Pratik Shah

Content Development Editor

Sachin Karnani

Technical Editor

Prajakta Mhatre

Copy Editor

Charlotte Carneiro

Project Coordinator

Neha Bhatnagar

Proofreader

Safis Editing

Indexer

Rekha Nair

Graphics

Abhinash Sahu

Production Coordinator

Aparna Bhagat

Cover Work

Aparna Bhagat

About the Author

Ramalingam Ganapathy is an independent computer software professional with more than 15 years of working experience of JavaScript and Google Apps Script. In 1985, he started his career as a digital electronic circuit designer and service engineer. Highly interested in reading technical books and building electronic projects, he is a detail-oriented and logical person. Since 2001, he has been freelancing with Elance and Upwork (formerly oDesk). He earned a good reputation on the Upwork portal, and most of his clients are satisfied.

I must thank and dedicate this book to my wife, Thiripurasundari, who served me coffee late at night. Also my son, Muhilan, and daughter, Rajalakshmi, who tested the code from the beginner's point of view.

About the Reviewer

Serge Gabet has been a professional audio equipment manufacturer for 20 years and is now working for an artistic upper school in Brussels, Belgium, as a teacher and technical manager. He is also in charge of the Google Apps administration of this school. He develops custom applications using Google Apps Script mainly for his school, though he also works in other areas.

He has been designated a top contributor by Google since June 2011. He was active on the Google Group Help forum until 2012, then on the Stack Overflow forum (the Google Help Group forum was closed in June 2012), and became a first ranker and an all-time contributor on the Stack Overflow forum a few months ago.

I'd like to thank all the forum contributors who were on the same forum at the time that I was new to the forum and helped me take my first steps. Most of them are now top contributors too, and even if their knowledge was (and still is) greater than mine, they never make me feel it. Thanks for that.

Also, thanks to Google collaborators for their day-to-day presence and for listening to our concerns.

www.PacktPub.com

eBooks, discount offers, and more

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

Google Apps is a collection of applications, namely, Gmail, Calendar, Drive, Docs, Sheets, and Forms. You can customize or automate Google Apps using the scripting language JavaScript with Google's defined classes. Google implements Google Apps Script (GAS) based on JavaScript.

Almost all Google Apps provide one or more services. GAS services and APIs provide easy access to automate tasks across Google products and third-party services. You can use these service classes in your GAS code to customize or automate Google Apps.

This book introduces basic things first before moving to advanced concepts step by step with practical code and examples. By reading this book, you'll gather expertise in Google Apps Script. Happy reading!

What this book covers

Chapter 1, Introducing Google Apps Scripts, tells you about Google Apps and gives you an introduction to Apps Scripts, explains how to create a project, and introduces custom formulas.

Chapter 2, Creating Basic Elements, covers many types of dialog and how to create and display them, how to use the Logger class to log values, and how to debug your script.

Chapter 3, Parsing and Sending E-mails, talks about the ContactApp, MailApp, and GmailApp services. Using these services, you'll create many useful real-world applications, including an e-mail merger application.

Chapter 4, Creating Interactive Forms, deals with creating Forms dynamically by script, publishing the script as a web application, creating Forms using HtmlService, creating an e-voting application, and creating a ticket reservation application.

Chapter 5, Creating Google Calendar and Drive Applications, teaches the reader to create Calendar events and sync events from one Calendar to another Calendar. This chapter also teaches how to enable GAS advanced services.

Chapter 6, Creating Feed Reader and Translator Applications, is about learning and creating many useful applications, including RSS/Atom reader and language translator applications.

Chapter 7, Creating Interactive Webpages, tells how to create an RSS feed/publisher, a file uploading application, and a full-blown timesheet application using HtmlService.

Chapter 8, Building a Workflow Application, explains how to create a workflow application and proceeds create a useful real-world order processing application.

Chapter 9, More Tips and Tricks and Creating an Add-on, is all about using external libraries including OAuth2, and Apps Script add-ons.

What you need for this book

You will need any modern browser and basic working or theoretical knowledge of HTML, CSS, and JavaScript.

Who this book is for

This book is for newbies to Google Apps Script who have less practical experience of web development and curious to gather expertise in customizing Google Apps and developing web apps.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "A default myFunction function will be there in the editor."

A block of code is set as follows:

function greeting() { Browser }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

</head> <body> <button onclick="alert('Hello World!');">Click Me</button> </body> </html>

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Go to Add-ons | Chapter 2 | Show Dialog and a modal dialog will pop up."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Introducing Google Apps Scripts

I know there may not be a single person in the world who has access to the Internet who has not used at least one of Google's products or services in their lifetime.

Google is known for its famous search engine, the video serving portal YouTube, and now by its numerous web applications, namely Gmail, Calendar, Drive, Docs, Sheets, and Forms. It also provides cloud computing and other software services.

The word "Google" has even become a verb, referring to conducting a web search. Nowadays, you hear people saying "I Googled something" rather than "I searched the web for something". In this chapter, you will learn about Google Applications, Application Scripts, and how to create a custom formula/function.

Google Applications

Google Applications are a collection of applications, namely Gmail, Calendar, Drive, Docs, Sheets, and Forms. From now on, we will use the term "Google Apps" or just "Apps".

Before we start, I'll quickly answer a few questions you may have:

Where do all these Apps run? On your computer?

No, all these Apps run on Google's Cloud-based servers.

How can you get access to these applications?

You can interact with these Apps through web browsers. No special hardware or software installations are required except for a modern web browser installed on your desktop, laptop, tablet, or smartphone.

Google Apps Script

You can customize or automate Google Apps using the JavaScript scripting language with Google-defined classes, known as Google Apps Script (GAS). Google implements GAS based on JavaScript 1.6 with some portions of 1.7 and 1.8. The GAS services and APIs provide easy access so users can automate tasks across Google products and third-party services.

You can write code in Google Docs, Sheets, and Forms using GAS and can automate tasks similar to what Visual Basic for Applications does in Microsoft Office. However, GAS runs on Google's server and the results are rendered in your browser. The integrated script editor allows you to edit and debug your scripts within your browser, and you do need not install anything. You can activate your debugged and tested script functions to run either based on your interactions or based on a trigger in response to an event or timed intervals (in minutes, hours, days, weeks, future dates, and so on). These events include onOpen, onEdit, onInstall, and many more. GAS is also used to create add-ons for Docs, Sheets, and Forms.

GAS can help you with every aspect of automating a task—you can even use it to order a pizza at predetermined date/time!

Visual Basic for Applications

Microsoft implements Visual Basic for Applications (VBA) to help automate Office applications such as Excel and Word. For each respective application, VBA is known as Excel VBA or Word VBA and so on. Using Excel VBA, you can create macros for Excel known as "Excel macros". GAS is for Google Applications, and operates in the same way as VBA does for Microsoft Office applications. Although both VBA and GAS do not require a separate compilation process, they are very different scripting languages and use different programming APIs, methods, and properties.

I hope many of you are familiar with using VBA for Office applications; if not, then never mind—that's not an obstacle to learning GAS.

The advantages of GAS over VBA

Version-independence: Sheets/Docs along with scripts are automatically saved in the cloud, attached to your Google account, and accessible from any computer with a browser. There is no need to worry whether the other computer has the same version of Sheets/Docs installed or not, whereas we can never be sure that one version of the Excel/Word macros will work on another version.Platform-independence: When you create VBA macros in Excel/Word on the Windows platform, they may not work on the Mac platform and vice versa. With Google Sheets/Docs, it doesn't matter what platform you're working on—it'll work.

The limitations of GAS

GAS runs on Google's server, so it cannot run continuously for more than six minutes (this may vary in the future). All of your functions should finish running and should return results within this time limit. Don't panic, as you'll learn how to use triggers effectively to overcome these limitations later.

In the following sections, we will take a look at the most popular Google Apps and how we can use GAS to customize and/or automate tasks.

Google Drive

Google Drive is a file storage application, which from now on we will just refer to as "Drive", where you can store and synchronize your files on Google's server. Let's look at some of the advantages of using Drive:

You can edit and share Google Docs, Sheets, and Forms with your friends or collaborators in real time.You can even stop editing a document on one of your desktops and continue with your smartphone or tablet, and vice versa, no matter where you are and what device you are using. This is possible because your files are stored on Google's Cloud server.Files created with Google Apps are stored in Drive with Google's native formats and extensions. For example, Google Docs (documents) files are .gdoc