-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learning Google Apps Script
By :

Scripts are organized as projects. Projects can be of two types, standalone and bounded to a gtype
(Google Drive native file type, such as Sheets, Docs, and Forms) file. Standalone scripts are created in a separate script file, you can see these files listed among other files in Drive. Bounded scripts are embedded within individual gtype
files and created using the respective applications. As you can see, the standalone script files, among other files in Drive, you can open directly from Drive, but bounded script can be opened within respective applications only. However, bounded script will have more privileges over parent file than standalone scripts. For example, you can get access to the active document within bounded scripts, but not within standalone scripts.
To create a standalone script file follow these steps:
Code.gs
, with a blank function, myFunction
, as shown in the following screenshot:Create a new Sheet or open the existing one. You will see a number of menu items at the top of the window. Now, follow these steps:
Although you can create as many bounded projects as you like, one project per file is enough. Creating just one project per file may help you to avoid problems with duplicate function and variable names.
Congratulations! You have created a new script project. By following the preceding steps you can create script projects in Docs and Forms too.
Open the spreadsheet you created earlier and make the following changes:
=CONCATENATE(A2," ", B2)
.Now you can see the first name and last name in cells A2 and B2 respectively, concatenated with a space in between.
CONCATENATE
is Google Sheet's built-in formula. You can also create your own, called custom formula:
function myFunction(s1,s2) { return s1 + " " + s2; }
Here is the screenshot for the same:
=myFunction(A2,B2)
.This works in exactly the same way as the built-in formula. You can extend your formula to other cells below C2. This is a simple formula, but you can create complex formulae as per your requirements.
Congratulations! You have created a custom formula.
To add code completion and/or tooltips for your custom function, add the following comments at the preceding lines of code in the function:
/** * Concatenates two strings * * @customfunction */ function myFunction(s1,s2){ …
Change the font size
Change margin width
Change background colour