Book Image

Google Apps Script for Beginners

By : Serge Gabet
Book Image

Google Apps Script for Beginners

By: Serge Gabet

Overview of this book

Table of Contents (16 chapters)
Google Apps Script for Beginners
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
7
Using User Interfaces in Spreadsheets and Documents
Index

Preface

A couple of years ago, I was asked by a colleague to create a form to collect invitation responses for a show that our school was organizing. Like most computer users, I had some experience with spreadsheets and had used them from time to time to do some basic calculations, so I created a form with the results in a spreadsheet.

At this point, I simply wanted to count the responses and show the result somehow. As I didn't know how to get a clear view of these results and a simple addition of numbers was not very attractive to look at, I decided to take a quick peek at the documentation to see how to write a "macro" to eventually get things to look better.

Three days later, the spreadsheet had a custom menu. It had functions that showed me the results in colorful tables and sent me an e-mail when too many people had made a reservation for the same day.

I discovered that this "macro" that I was looking for had a lot more features than that; I had a whole bunch of tools and services that I was able to customize exactly to what I needed, without spending a single cent on it.

This was the end of my ''peaceful life without Google Apps Script'' and the beginning of a real adventure. I didn't know a single word of JavaScript or HTML. My only programming experience was using BASIC on an 8-bit microcomputer from the 1980s, so I knew that there would be a few things to learn.

This happened in 2009. At the time, Google Apps Script was just beginning its development. As it has grown a lot since then, it has provided an opportunity for my skills to improve as well. At that time, I found help from a couple of guys on the Google group help forum (now closed and wiped out). Thanks Henrique, scampmichael, and velosprinter—they know who they are.

I know that each of us has a different background and follows a different path but, nevertheless, I decided to present this book following the same progression that I had followed—from basic spreadsheet enhancement and customization to standalone web apps with really powerful features. In between, we shall see that other documents can have embedded scripts and that most of the Google services can communicate with Google Apps Script.

There is probably no way to present every possible combination of scripts and methods that are available exhaustively in a single book. But, I'll try to pick up the most useful and interesting ones based on what I see every day on the well-known help site where I participate a lot: http://stackoverflow.com/questions/tagged/google-apps-script.

What this book covers

Chapter 1, Enhancing Spreadsheets, is an introduction to JavaScript as a spreadsheet macro language. It shows you how many aspects of a spreadsheet document could be modified using Google Script—not only layout and formatting but sharing and publishing as well.

Chapter 2, Create and Manipulate Forms, deals with an automated form creation and modification with Google Apps Script. It demonstrates the ability of forms to respond to triggers, thereby automatically sending an evaluation with reference to good and bad answers.

Chapter 3, Managing an E-mail Account, shows you how to send messages, filter your messages, and combine Gmail with documents to create your own workflow. You will learn that Google service offers an impressive panel of methods that allows for almost any possible manipulation of your mailbox content.

Chapter 4, Embedding Scripts in Text Documents, shows you how to build and analyze Google documents using JavaScript. You will also see how to build or change a document's content and how to analyze what is already present in the document.

Chapter 5, Embedding Scripts in Google Sites, demonstrates how a script updates your Google site automatically. This chapter also demonstrates the multiple aspects and advantages of the communication and combination of multiple services.

Chapter 6, Standalone Web Applications / User Interfaces, teaches you how to create web applications that work everywhere and that anyone can use. It also shows you how to protect your private data across the Internet.

Chapter 7, Using User Interfaces in Spreadsheets and Documents, empowers you to use your new skills to create more user-friendly documents and worksheets. It will simplify your work with spreadsheets and documents to either show data in a way that is not directly available or to add extra functionalities.

Chapter 8, How to Expand Your Knowledge, gives you tips and tricks to learn what this book could not cover. It will give you an overview of the many resources available to help improve your learning experience.

Chapter 9, Conclusion, ends with perspectives, secrets, and the author's personal point of view.

What you need for this book

You need only an Internet connection and a modern browser, although any browser should work without restriction. As most of the code is executed on a distant server, some rendering may differ if you use an old version of Microsoft Internet Explorer.

I would recommend you to use Google Chrome as it will automatically offer you one of the best compatibility performances and updates.

Besides that, you won't have to install anything.

Who this book is for

Do you like the idea of having some tasks executed automatically for you and want to get things done more simply? That's exactly the purpose of this book.

You won't need any preliminary knowledge to start reading, but be prepared to learn a lot of things in a short time. Being comfortable with basic text writing and manipulation such as copy and paste are mandatory requests.

Conventions

In this book, you will find a number of styles of text 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 inputs, and Twitter handles are shown as follows: "As you can notice, we use #name# to mark the placeholders."

A block of code is set as follows:

var docCopy = DriveApp.getFileById(sharedDocID).makeCopy('menu['+headers[todayInSheet]+']');
  menuFolder.addFile(docCopy);
  DriveApp.getRootFolder().removeFile(docCopy);

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

function myAgeInHours(){
  var myBirthDate = new Date('1958/02/19 02:00:00').getTime();
  myBirthDate = parseInt(myBirthDate/3600000, 10);

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Open the script editor from the Tools menu and write the code snippet we just prepared.".

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 may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through 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 on 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 all Packt books you have purchased 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.

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 would 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/support, 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.

Piracy

Piracy of copyright 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.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.