Welcome folks today in this blog post we will be
emailing the data of whole google sheet as a pdf document in spreadsheet editor. All the full source code of the application is shown below.
In order to get started you need to go to google sheets and create a new sheet as shown below. And after that you need to insert some data as well in that sheet so that we will email the data to the user.
Now we need to draw a button guys inside the google spreadsheet so that when we click that button our script will run in the background to send the sheet data as an pdf to the email address. You can insert the button as shown below
Now we need to assign the script to this button. So whenever we click this button what script should run. We will name our script as
emailsheet as shown below
Now we need to enter this
function that we have assigned inside the
google apps script editor. Open it using the menu as shown below
Now we will be writing the
app script code guys. So just copy paste the below code
var ss = SpreadsheetApp.getActiveSpreadsheet();
var filename = "A Copy of " + ss.getName();
var MyNewBook = ss.copy(filename);
var MyUser = "firstname.lastname@example.org";
subject: 'TEST title',
body: 'TEST body',
attachments: [MyNewBook.getBlob().setName(filename + ".pdf")]
As you can see we are getting all the data of the current
google spreadsheet and then sending it as the pdf document to the specified email address. Just change the email to your target email.
And now guys if you to the google sheets and if you try to press the button your script will run you need to allow the permissions as shown below