Google Sheets and App Script Beginner's Guide - Part 1 - Written by Sean Yeh - Web Design Zone - Medium - February 2023 - Web Design Zone
Google Sheets and App Script Beginner's Guide - Part 1 - Written by Sean Yeh - Web Design Zone - Medium - February 2023 - Web Design Zone
Get unlimited access to the best of Medium for less than $1/week. Become a member
GAS can use JavaScript as its programming language, allowing developers to use
JavaScript to create automation tools and applications for Google Spreadsheets,
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY3… 1/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Google Forms, Google Documents, and other Google applications. It has the
following advantages:
Welcome back. You are signed in as zu•••••••@gmail.com.
Easy to use: Since GAS is based on the JavaScript programming language, which is a
very universal language, it has a relatively simple learning curve for most
developers.
Open
Integrated: GAS can be integrated with in appservices in the Google Workspace,
many
such as integrating Gmail, Calendar, Cloud Drive, and services like Google Forms,
Search
Google Spreadsheets, Google Documents, etc.
Extend Google applications: GAS can extend and automate Google applications and
integrate with the APIs of various Google services and third-party APIs. For
example, YouTube API, Google Maps API, etc., it can even be used to develop your
own Google applications. From the perspective of extending Google services, its role
is similar to Microsoft VBA for the Office suite of software.
Operates in the cloud server: GAS can operate on Google’s servers and directly
access data located on Google’s servers. This design avoids the bottleneck of local
server hardware performance and allows for development anytime, anywhere.
Develop and deploy anytime, anywhere: Since GAS operates on Google’s servers, the
written code can be executed directly in the browser, and developers can develop,
execute, and debug anytime, anywhere without geographic location restrictions, as
long as there is an internet connection.
Free: Finally, using GAS is free and does not require any additional costs.
Google Spreadsheet has similar functions and interfaces to Microsoft Excel. It can
store various values and formulas in tables, create charts, and even export and
import different spreadsheet file formats. Therefore, we sometimes use Google
Spreadsheet as a database role. By using Google App Script to write programs to
automate routine tasks in our daily lives, we can increase efficiency. Therefore, we
choose Google Spreadsheet to explain some common ways and syntax of using
Google App Script.
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY3… 2/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Installing GAS
Before you start writing
Welcome the
back. program,
You are signed you need to make sure the Google App Script
in as zu•••••••@gmail.com.
package is installed (as shown in picture one). The Google App Script package is a
default application, and if you can’t find the package, you will need to install it
manually (as shown in picture two).
First, go to the cloud drive, click on “New | More”, and see if you can see the option
for the Google App Script package?
If you can find the select option for Google App Script, it means it is already
installed. If you cannot find it, you need to install it from “New | More | Connect
more apps.”
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY3… 3/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Developing Environment
After entering the cloud disk and clicking on “Add | More | Google App Script,” you
will see the following screen. This is the Google App Script development
environment, also known as the IDE. The environment displays different colors for
different variables, reserved words, etc., making it as easy to use as a general IDE.
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY3… 4/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
To know the IDE, we can divide it into three sections: the top, the left, and the
center. Welcome back. You are signed in as zu•••••••@gmail.com.
The part on top contains the project name and the deployment button.
The left-side menu is the project’s settings column and file list. The settings column
can set various functions and triggering conditions related to the project, while the
file list can create file formats including script files (.gs) and HTML files.
The center part of the IDE is the code editor where the developer can write code.
Above the editing area is the quick function bar that allows the developer to save,
execute, and debug.
Therefore, there are two ways to create a Google App Script project:
Create a Google spreadsheet (or start by using other Google App application) first,
and then open the script editor from the menu of the spreadsheet. By this way, the
code was written as attached to the Google Workspace service. The example is as
seen in the green icon in the picture below. Add a Google App Script file directly
from the cloud drive. The newly added file will operate as an independent file. As
seen in the blue icon in the picture below.
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY3… 5/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
In the development process of a Google App Script project, interaction with various
Google App applications must be done through the Google App Script API. The
operation and usage of each application are different, so the usage will also be
different. Google App Script provides various APIs for developers to easily call and
use for different Google applications.
Google App Script operates on applications through classes, each application has
different class names, such as DriveApp for Google Drive and DocumentApp for
Google Documents, etc. If you want to interact with Google Spreadsheet through
Google App Script today, you need to know the operation of SpreadsheetApp. The
following introduces several common operation methods in Google Spreadsheet.
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY3… 6/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
The following shows how to create a new spreadsheet, retrieve information from
the spreadsheet, or open
Welcome back.an
Youexisting
are signedspreadsheet so that you can perform the
in as zu•••••••@gmail.com.
operations afterword.
Creating a Spreadsheet
The following commands help you create a new spreadsheet by using Google App
Script:
create(name)
The method “create” in SpreadsheetApp allows us to create a new Google
spreadsheet. As shown in the example below, the parameter for create is the name
of the spreadsheet.
function myFunction() {
var ss = SpreadsheetApp.create('New Test Sheet');
Logger.log(ss.getUrl());
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY3… 7/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
This method not only allows us to create a new Google Spreadsheet, but also you can
creates a new one with the given name and the specified number of rows and
columns. By adding numbers of rows and columns you want in the parameter, you
can pre-specify the number of rows and columns in the new spreadsheet.
function myFunction() {
var ss = SpreadsheetApp.create('New Test Sheet2',30,20);
Logger.log(ss.getUrl());
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY3… 8/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Note: In the equation above, you can see the following line, through Logger.log()
you can display the desired information. Its function is similar to console.log() in
JavaScript, where ss.getUrl() will get the path of the spreadsheet that you newly
created.
Logger.log(ss.getUrl());
As shown in the figure below, the spreadsheet which produced by the code above,
has already pre-designated 20 columns (from column A to column T) and 30 rows
(from row 1 to row 30).
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY3… 9/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Logger.log(ss.getUrl());
The following method can be used to retrieve the URL of the spreadsheet:
function myFunction() {
var ss = SpreadsheetApp.create('New Test Sheet',30,20);
url = ss.getUrl()
Logger.log(url);
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 10/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
The URL information will be displayed in the “Execution log” (as shown in the
figure below) Welcome back. You are signed in as zu•••••••@gmail.com.
getId()
Besides the URL of the spreadsheet, if you want to retrieve the ID of the
spreadsheet, you can use the following code:
function myFunction() {
var ss = SpreadsheetApp.create('New Test Sheet',30,20);
Id = ss.getId()
Logger.log(Id);
After run the code shown above, you will get a string with spreadsheet ID that
displayed in the “Execution log”.
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 11/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
getName()
It can retrieve the name of the spreadsheet.
function myFunction() {
var ss = SpreadsheetApp.create('New Test Sheet',30,20);
name = ss.getName()
Logger.log(name);
After run the code, the name of the spreadsheet, New Test Sheet, will appear in the
“Execution log” .
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 12/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
By retrieve URL and ID of the spreadsheet, we can perform other operations on the
spreadsheet through them in the future.
Open A Spreadsheet
How to open a spreadsheet that already being created?
openById(id)
SpreadsheetApp.openById(id) is a function in Google App Script that allows us to
open a Google spreadsheet using a unique identifier represented by the id
parameter. The function returns a Spreadsheet object, providing subsequent access
to read data on the spreadsheet.
function myFunction() {
var ss = SpreadsheetApp.openById('th id of the spreadsheet');
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 13/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Logger.log(ss.getName());
}
Welcome back. You are signed in as zu•••••••@gmail.com.
As shown in the following image, executing the above code will display the name of
the corresponding id spreadsheet.
openByUrl(url)
SpreadsheetApp.openByUrl(url) is another GAS function that allows you to open a
spreadsheet by using its URL. The URL is represented by the url parameter. This
function will also return a Spreadsheet object, and providing subsequent access to
the data in the spreadsheet.
Therefore, the spreadsheet can be opened simply by providing the spreadsheet URL
as a parameter in the openByUrl function.
The following code, as an example, which has the only difference from the previous
openById code. Being that openById is changed to openByUrl , and the input value
must also be changed to the URL.
Run the code. The “Execution log” will display the name of the spreadsheet.
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 14/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
function myFunction(){
Welcome back. You are signed in as zu•••••••@gmail.com.
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/id/
Logger.log(ss.getName());
}
Conclusion
So far, we have been able to create Google spreadsheets through Google App Script,
which is a convenient tool to help us automate data processing. In the process, we
can create the spreadsheet template we need by setting parameters. In addition, we
can also carry out activities to open files and edit or modify existing Google
spreadsheets.
In Google App Script, we can use either the openById or openByUrl method to open
spreadsheets, where the former opens the spreadsheet through its ID, while the
latter opens it through its URL. The usage is similar, with differences only in the
parameters.
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 15/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Due to space constraints, this is where we will stop for now. In the next article, we
will go into detail about
Welcome how
back. Youto
areoperate
signed in the cells in Google spreadsheets. This will be
as zu•••••••@gmail.com.
a very important stage as we will be processing, analyzing and summarizing data in
Google spreadsheets to help us better understand the data. If you are interested in
Google App Script, then the next article will be an important content that you
cannot miss.
Next:
如果要看中文版,請點選這裡。
GoogleAppScript-改造你的Google試算表-1
什麼是GoogleAppScript
medium.com
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 16/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Follow
pandas基礎介紹-進入資料科學的領域
什麼是pandas?乍聽這個字或許你的第一個直覺反應會是那可愛的熊貓。
220
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 17/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
MySQL資料庫的安裝與基本操作
在日常生活中,當我們對於與他人在交易時做了一些紀錄、或者是對於團體中的各個成員的資
料做紀錄時,除了透過傳統的紙張將一項項的內容一張張的紀錄下來放在檔案櫃中,還有什麼…
17
在Vue.js中使用Axios取得資料
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 18/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Vue如果需要取用網站外其他的資料,需要借助於第三方的資源。Axios是其中的一種。
Welcome back. You are signed in as zu•••••••@gmail.com.
12 min read · Mar 14, 2022
82 1
Python- lambda 函式
lambda函式
73
Tarun Telang
Shad Humydee
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 20/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Lists
Leadership upgrades
7 stories · 78 saves
Mathias Wagner
113 1
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 22/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
Dhruv Singhal
Baz Roberts
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 23/24
28/05/2024, 13:48 Google Sheets and App Script Beginner's Guide - Part 1 | Written by Sean Yeh | Web Design Zone | Medium | February 2023 | Web Design …
When working with spreadsheets we want to be able to enter data as quick as possible and to
make it as easy Welcome
as possible.
back.Here, we’re
You are going…
signed in as zu•••••••@gmail.com.
1 1
https://medium.com/web-design-zone/the-beginners-guide-to-google-sheets-and-app-script-1-86e5095887bb#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjY… 24/24