Google Apps Script Tutorial to Email Google Sheet as PDF Document on Button Click in SpreadSheet
Dec 21, 2025
Buy the full source code of application here:
https://buy.stripe.com/7sI3fw7Jf8gM57q5Lh
Show More Show Less View Video Transcript
0:00
Uh hello friends today in this tutorial
0:02
I will be showing you that how to email
0:04
the use the data which is present inside
0:07
your Google sheet spreadsheet as a PDF
0:10
document to your email address. So let's
0:12
suppose you have this data here we have
0:15
name country we have four columns out
0:17
there four rows out there and it's a
0:19
button out there. So whenever I click
0:21
this button guys all this data will be
0:23
captured and it will be emailed to my
0:26
this one. So let me show you step by
0:28
step as I hit this button guys what
0:30
should happen now inside Google app
0:32
script it will execute this function in
0:34
the background let me hit this button
0:35
here send report you will see it is
0:37
running the script here and uh as soon
0:40
as this script is ending you will see
0:42
finish script I will get a message here
0:44
you will see on the right hand side I
0:45
got a message and basically it will have
0:48
this as a PDF document if I open this
0:50
you will see all this information would
0:52
be there name country John Williamson us
0:54
and you will see that four column four
0:56
rows are there and it has simply
0:58
captured the screenshot as the image and
1:00
emailed me as a PDF document. So I can
1:02
even download this as a PDF document. So
1:05
you will see that if I open this inside
1:07
my browser, you can print it out. So
1:10
it's a multiple users are there. So you
1:12
can capture the information inside your
1:14
Google sheet and then you can also email
1:16
this as a PDM document as well. So it's
1:18
very easy step-by-step process. I will
1:21
show you how to do this process and for
1:23
this I have written a complete blog post
1:25
on my tutorial website which is web
1:27
ninja developer.com. So you can go to
1:29
this blog post. The link is given in the
1:31
description of this video. So I have
1:33
explained each step in detail with
1:36
instructions and all the source code is
1:38
also given. So let's start building this
1:40
application guys from scratch. So first
1:43
of all, if you don't know about Google
1:45
Appcript guys, it's a scripting language
1:48
developed by Google. And if you just
1:51
type Google Appcript, basically this is
1:53
the language we will use. So it is used
1:55
to communicate with the Google APIs that
1:57
you have such as Google Drive, YouTube
2:00
or Gmail, spreadsheet, all those stuff,
2:02
Excel. So specifically here we are using
2:06
our Google sheet. So just type Google
2:08
sheet here and go to Google sheet here
2:11
and click on go to sheets and here we
2:13
will create a blank sheet guys and
2:16
basically we can rename this. You can go
2:18
to file here click on rename and we here
2:20
you can say that uh our uh player data.
2:26
So inside player data guys we will have
2:28
uh two columns out there name age and
2:32
country as well. three columns. You can
2:34
have as many columns as you want guys.
2:36
Totally depends upon you. Let me insert
2:40
the details out there.
2:45
And uh let me
2:48
you can have your data coming from a
2:50
database or anything else API totally
2:53
depends upon you.
2:59
Let me just add this here.
3:05
So we have four columns out there guys
3:08
which we will be emailing here.
3:14
So now guys you can see that we have uh
3:16
four rows out there and now we have to
3:19
have a simple button so that when we
3:21
click that button we need to execute the
3:24
script in the background. So in order to
3:26
draw a button guys simply go to this
3:28
insert option here in menu bar and here
3:31
is a option called as drawing option. So
3:34
simply select this and after this you
3:36
need to draw a shape out there. Simply
3:38
go to shape out there and simply select
3:40
your shape which is this one and right
3:43
here simply draw it. And here we can
3:45
simply say that send report.
3:49
You can just customize the text
3:50
accordingly and resize the button like
3:53
this. And also you can move this button
3:56
like this here also just to place it.
3:59
And after that you simply need to click
4:01
save and close. So now your button will
4:04
be there guys. You will see that inside
4:05
your Google sheet. And basically here we
4:08
can assign it. Simply right click. And
4:11
here you will see these three dot
4:13
options. Simply click it. And this is
4:15
the third option that you need to select
4:17
which is assign script. So it is telling
4:20
me what script do you want to assign. So
4:22
here we need to assign the name of the
4:24
function that we will be executing. Let
4:26
me email sheet. This is the function we
4:29
would write. Simply click on okay.
4:32
That's it. So now when you click this
4:34
button guys, you will see script
4:36
function could not be found. So we need
4:38
to write this function. Go to your
4:40
extensions appcript and here we will
4:42
write our appcript code guys. This is
4:44
your editor here where you can create
4:47
projects and deploy it on the live
4:50
internet as well. So now we will write
4:52
this function guys which we have written
4:53
which is email sheet. So this is a
4:56
function. So basically it's scripting
4:59
language. If you are comfortable with
5:01
JavaScript you will be understanding all
5:03
the concept here. It's a JavaScript
5:05
language. And here you will be first of
5:07
all be getting the reference of the
5:09
spreadsheet current spreadsheet. You can
5:12
use the spreadsheet app library for
5:14
this. This contains a method which gets
5:16
the current active spreadsheet. This is
5:19
a method that we will invoke. Get active
5:22
spreadsheet. Simply invoke this method.
5:25
Now this will be basically you can see
5:27
there are lots of sheets out there.
5:29
Sheet one, sheet two. You can even add
5:31
sheet two as well. Sheet one. You can
5:34
add as many sheets as you want. So
5:37
basically you can see that. So we are
5:39
simply getting the reference to the
5:41
current sheet which the name of the
5:43
sheet is sheet one. So after this guys
5:46
we need to first of all get the file
5:48
name. So we will simply say a copy of
5:52
and then we will simply get the name of
5:54
the sheet which is sheet one. So get
5:58
name we have the method here get name.
6:01
That's it. So this will output a copy of
6:04
sheet one. You can even rename your
6:07
sheet name as well guys. Simply go to
6:08
rename and simply change it here to
6:11
player sheet. Let me just rename this.
6:14
You will see now this sheet has been
6:16
renamed to player sheet. And after this
6:19
guys after getting the file name we will
6:21
now be declaring my new book. And simply
6:26
we will copy this copy all the content
6:29
which is there inside the sheet. All the
6:32
columns all the rows out there. It will
6:34
copy all the data alongside with this
6:36
button as well. It will take a
6:38
screenshot.
6:40
After this guys, we need to
6:44
put the email address to which you need
6:45
to send out it. So I will choose this
6:49
email address. After this
6:52
you will be using this mail app guys.
6:54
Mail app library and this contains a
6:56
method called called as send email which
6:59
will actually send this spreadsheet as a
7:02
PDF document. And here this takes some
7:05
options. The first option is the two
7:07
option and here we will be sending to
7:10
the email address that we have specified
7:12
here. So we will simply say email. The
7:14
second option it takes is the subject
7:16
property guys. So we will simply say uh
7:19
player info
7:22
and uh the body we will simply say
7:28
this is the
7:30
sheet. This is a player
7:34
information sheet.
7:37
After this guys, we need to add a
7:39
attachment here. There's also attachment
7:42
property. So here you can se just attach
7:45
your images, PDF documents alongside
7:47
with the email address. So this is an
7:49
array guys. Basically here we will be
7:51
attaching my new book and here we will
7:54
be converting it to a blob object. So we
7:57
will say get blob. So basically it will
8:00
return the data inside this object as a
8:02
blob. If you don't know about a blob
8:04
guys basically uh whenever you try to
8:07
export your images you can export it to
8:09
a blob object. And now we simply need to
8:12
set this a name here. This is a method
8:16
here set name. So we will set the name
8:20
for this block alongside with the PDF
8:22
extension. So file name is there. We can
8:25
see file name is there. So we can just
8:27
add extension of PDF. That's it. That's
8:30
all that you need to write code guys.
8:32
This is your code guys. It will take the
8:34
screenshot of this spreadsheet as a
8:37
image and it will insert it in the PDF
8:39
document and it will mail this inside
8:42
this email address. That's it. Now
8:44
simply save your project guys. Simply
8:46
save your project. And now if you click
8:49
this button send report you will see it
8:51
will run your script and basically it
8:53
will ask for the permission whenever it
8:56
runs for the very first time. So it will
8:58
first of all you need to allow the
9:00
permission here you will see
9:02
authorization required. So you need to
9:04
click continue and basically allow the
9:06
permission. Simply select your account
9:08
here and go to advanc and go to this one
9:13
and uh simply allow the permissions.
9:15
This will edit, create and delete all
9:17
your Google sheet spreadsheet and also
9:19
it will send the email as well. So
9:21
simply click allow here and after this
9:24
guys it will authorization is
9:26
successful. And now if you check your
9:31
if I check my this one you will see that
9:38
authorization is successful.
9:45
I think we need to click this button
9:48
once again. Running script. So now you
9:50
will see after you run the script here.
9:54
Finished script. Now if you check you
9:56
will see player info. This is a player
9:59
information sheet and this is a PDF
10:01
document which is attached here. If you
10:03
open this you will see that all the
10:05
three columns are there. Four rows are
10:07
also there. This is a button. So
10:08
basically it has taken the screenshot as
10:10
a PNG image or inserted it in the PDF
10:13
document. So you can now download this
10:15
as a PDF document and simply print it
10:18
out like this. You will see that it can
10:21
contain as many rows as you want guys.
10:23
So basically this is a nice little
10:25
functionality you can develop. Anytime
10:27
you click send report it will
10:29
automatically send out to the specified
10:32
email address. And you can even
10:33
customize this. Let's suppose you want
10:35
to just put a comma here if you want to
10:38
send out to multiple people. So you can
10:41
even do that as well. So here you can
10:44
mention
10:46
the second email address.
10:49
So now what will happen? It will send
10:51
out to multiple people. So save your
10:54
project. And now if you click send
10:55
report. So it is running the script once
10:58
again. And once again when it finishes.
11:02
Now if I check the second email,
11:05
click on Gmail.
11:08
You will also see guys clear info. You
11:12
can see the same data is received here
11:14
also. Let me select my second one.
11:22
You will now see once again this same
11:24
data would be there. You can see for the
11:26
second time it is received here. So in
11:28
this way you can also just uh send it to
11:31
multiple people at once also with with a
11:33
single click send report in the Google
11:36
sheet. So that's all guys from this
11:39
video. Please hit that like button
11:41
subscribe the channel and if you want
11:43
the full source code of the script you
11:44
can go to the description of this blog
11:47
post I have of this video. I have
11:50
written a complete blog post. So I will
11:53
be seeing you in the next
