OfficeScript package
Interfaces
OfficeScript.EmailAttachment |
The attachment to send with the email. A value must be specified for at least one of the |
OfficeScript.MailProperties |
The properties of the email to be sent. |
Enums
OfficeScript.EmailContentType |
The type of the content. Possible values are text or HTML. |
OfficeScript.EmailImportance |
The importance value of the email. Corresponds to "high", "normal", and "low" importance values available in the Outlook UI. |
Functions
Office |
Return the text encoding of the document as a PDF. If the document is empty, then the following error is shown: "We didn't find anything to print". Some actions made prior to using this API may not be captured in the PDF in Excel on the web. |
Office |
Downloads a specified file to the default download location specified by the local machine. |
Office |
Get the name of the currently running script. |
Office |
Saves a copy of the current workbook in OneDrive, in the same directory as the original file, with the specified file name. The API has a timeout limit of 30 seconds. This limit is rarely exceeded. Note: Timeout doesn't necessarily indicate that the API failed. The workbook copy may still be created, but after the timeout limit this API does not return a success or failure message. Throws: Throws: Throws: Throws: |
Office |
Send an email with an Office Script. Use |
Function Details
OfficeScript.convertToPdf()
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Return the text encoding of the document as a PDF. If the document is empty, then the following error is shown: "We didn't find anything to print". Some actions made prior to using this API may not be captured in the PDF in Excel on the web.
export function convertToPdf(): string;
Returns
string
The content of the workbook as a string, in PDF format.
Examples
/**
* This script saves a worksheet as a PDF and emails that 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.
// Email the PDF.
OfficeScript.sendMail({
to: "name@email.com", // 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]
})
}
OfficeScript.downloadFile({
name,
content,
})
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Downloads a specified file to the default download location specified by the local machine.
export function downloadFile({
name,
content,
}: {
name: string;
content: string;
}): void;
Parameters
- { name, content, }
-
{ name: string; content: string; }
Returns
void
OfficeScript.Metadata.getScriptName()
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Get the name of the currently running script.
export function getScriptName(): string;
Returns
string
OfficeScript.saveCopyAs(filename)
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Saves a copy of the current workbook in OneDrive, in the same directory as the original file, with the specified file name. The API has a timeout limit of 30 seconds. This limit is rarely exceeded. Note: Timeout doesn't necessarily indicate that the API failed. The workbook copy may still be created, but after the timeout limit this API does not return a success or failure message.
Throws: ExternalAPITimeout
The error thrown if the API reaches the timeout limit of 30 seconds. Note that the copy may still be created.
Throws: InvalidExtensionError
The error thrown if the file name doesn't end with ".xlsx".
Throws: SaveCopyAsFileMayAlreadyExistError
The error thrown if the file name of the copy already exists.
Throws: SaveCopyAsFileNotOnOneDriveError
The error thrown if the document is not saved to OneDrive.
export function saveCopyAs(filename: string): void;
Parameters
- filename
-
string
The file name of the copied and saved file. The file name must end with ".xlsx".
Returns
void
OfficeScript.sendMail(mailProperties)
Note
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Send an email with an Office Script. Use MailProperties
to specify the content and recipients of the email. If the request body includes content, this method returns 400 Bad request.
export function sendMail(mailProperties: MailProperties): void;
Parameters
- mailProperties
- OfficeScript.MailProperties
Returns
void