Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29758

Google Script - Send active sheet as PDF to email listed in cell

$
0
0

I'm trying to use the script below to send the first sheets in a Google Sheets document to an email as PDF. The email to send to, is listed in cell A1.

However, this script send the entire spreadsheet as an PDF and not just the first sheet. I have been trying to use some of the other scripts from stackoverflow, but this is the only one that actually sends an email.

Hope you guys can help me out.

        /* Email Google Spreadsheet as PDF */function emailGoogleSpreadsheetAsPDF() {  // Send the PDF of the spreadsheet to this email address  var email = "amit@labnol.org";   // Get the currently active spreadsheet URL (link)  var ss = SpreadsheetApp.getActiveSpreadsheet();  // Subject of email message  var subject = "PDF generated from spreadsheet "+ ss.getName();   // Email Body can  be HTML too   var body = "Install the <a href='http://www.labnol.org/email-sheet'>Email Spreadsheet add-on</a> for one-click conversion.";  var blob = DriveApp.getFileById(ss.getId()).getAs("application/pdf");  blob.setName(ss.getName() +".pdf");  // If allowed to send emails, send the email with the PDF attachment  if (MailApp.getRemainingDailyQuota() > 0)     GmailApp.sendEmail(email, subject, body, {      htmlBody: body,      attachments:[blob]         });  }

Viewing all articles
Browse latest Browse all 29758

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>