I have located some similar posts but none of the solutions seemed to work.

I have a function that sends me an email PDF of a spreadsheet. I just want the email attachment to send the first sheet (tab) in the spreadsheet which is just titled "Report" I don't want it to send the other tabs. Can someone help me modify the script below to just send the first tab?

The script I have so far is:

function publish() 

{ var message = { to: "Redacted email address", 

subject: "Report",

    body: "Attached is the report",

    name: "Report",

    attachments: [SpreadsheetApp.getActiveSpreadsheet().getAs(MimeType.PDF).setName("Report")]

1 Answer 1


You can get the active sheet as PDF like this:

const ss = SpreadsheetApp.getActive();
const sheet = ss.getActiveSheet();
const url = `https://docs.google.com/spreadsheets/d/${ ss.getId() }/export?exportFormat=pdf&gid=${ sheet.getId() }&access_token=${ ScriptApp.getOAuthToken() }`;
const blob = UrlFetchApp.fetch(url).getBlob().setName(`Report - ${ sheet.getName() }`;

Then set attachments: [blob].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.