Skip to content

[admin] Publish #790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Combine workbooks into a single workbook
description: Learn how to use Office Scripts and Power Automate to create merge worksheets from other workbooks into a single workbook.
description: Learn how to use Office Scripts and Power Automate to merge worksheets from other workbooks into a single workbook.
ms.date: 11/29/2023
ms.localizationpriority: medium
---
Expand Down
55 changes: 55 additions & 0 deletions docs/resources/samples/save-as-pdf-email-as-pdf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: Save and email as a PDF
description: Use Office Scripts to save a worksheet as a PDF and then email that PDF.
ms.date: 07/03/2025
ms.localizationpriority: medium
---

# Save a worksheet and email it as a PDF (preview)

Use Office Scripts to save a worksheet as a PDF and email it to yourself or your team.

> [!NOTE]
> The script in this sample is provided as a preview for developers and may change based on feedback that we receive. Do not use this script in a production environment.

## Solution

1. Create a new Excel file in your OneDrive.
1. Add data to your workbook.
1. Create the script from this sample.
1. Replace `[email protected]` in this sample with your desired recipient email address.
1. Adjust the `subject` and `content` values.
1. Run the script.

## Sample code: Save as a PDF and send via email

```TypeScript
/**
* This script saves a worksheet as a PDF, downloads that PDF to your computer, and emails the PDF to a recipient.
*/
function main(workbook: ExcelScript.Workbook) {
// Create the PDF.
const pdfObject = OfficeScript.convertToPdf();
const pdfFile = { name: "report.pdf", content: pdfObject }; // Enter your desired PDF name here.

// Download the PDF.
OfficeScript.downloadFile(pdfFile); // Not required. Remove this line if you don't want to download the PDF.

// Email the PDF.
OfficeScript.sendMail({
to: "[email protected]", // Enter your recipient email address here.
subject: "[Demo] Monthly Sales Report", // This is the subject of your email.
content: "Here's the Monthly Sales Report", // This is the content within your email.
attachments: [pdfFile]
})   
}
```

> [!TIP]
> Use the properties of the [MailProperties](/javascript/api/office-scripts/excelscript/global.officescript.mailproperties) interface to add more details to your email, such as `cc`, `bcc`, and `importance` values.

## Troubleshooting

### Error: Protected document

The [sensitivity label](https://support.microsoft.com/office/2f96e7cd-d5a4-403b-8bd7-4cc636bae0f9) for your workbook is preventing the script from sending an email. To resolve this error, change the sensitivity label of your workbook to General, Public, or Non-Business. Reload the workbook, and then run the script again.
2 changes: 2 additions & 0 deletions docs/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ items:
href: resources/samples/excel-calculation.md
- name: Move selected rows across tables
href: resources/samples/move-rows-across-tables.md
- name: Save and email as a PDF
href: resources/samples/save-as-pdf-email-as-pdf.md
- name: Notify people with comments
href: resources/samples/add-excel-comments.md
- name: Output table data as JSON
Expand Down