Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Google Apps Script Tutorial to Email Google Sheet as PDF Document on Button Click in SpreadSheet Editor

Posted on November 26, 2022

 

 

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.

 

 

Get Started

 

 

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

 

 

code.gs

 

 

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
function emailsheet(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var filename = "A Copy of " + ss.getName();
var MyNewBook = ss.copy(filename);
var MyUser = "harshadchopra1997@gmail.com";
MailApp.sendEmail({
  to: MyUser,
  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

 

Recent Posts

  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme