OfficeScript package
インターフェイス
| OfficeScript.DownloadFileProperties |
ダウンロードするファイル。 |
| OfficeScript.EmailAttachment |
メールと共に送信する添付ファイル。
|
| OfficeScript.MailProperties |
送信するメールのプロパティ。 |
列挙型
| OfficeScript.EmailContentType |
コンテンツの種類。 指定可能な値は、テキストまたは HTML です。 |
| OfficeScript.EmailImportance |
電子メールの重要度値。 Outlook UI で使用できる重要度値 "high"、"normal"、"low" に対応します。 |
関数
| Office |
ドキュメントを PDF に変換し、そのテキスト エンコーディングを返します。 |
| Office |
指定したファイルを、ローカル コンピューターで指定された既定のダウンロード場所にダウンロードします。 |
| Office |
現在実行中のスクリプトの名前を取得します。 |
| Office |
OneDrive 内の現在のブックのコピーを、指定されたファイル名で元のファイルと同じディレクトリに保存します。 この API は、他の API の前に呼び出す必要があります。 |
| Office |
Office スクリプトを使用してメールを送信します。
|
関数の詳細
OfficeScript.convertToPdf()
ドキュメントを PDF に変換し、そのテキスト エンコーディングを返します。
export function convertToPdf(): string;
返品
string
PDF 形式の文字列としてのブックのコンテンツ。
スロー:ConvertToPdfEmptyWorkbook ドキュメントが空の場合にスローされます。
スロー:ConvertToPdfProtectedWorkbook ドキュメントが保護されている場合にスローされます。
スロー:ExternalApiTimeout API がタイムアウト制限の 30 秒に達した場合にスローされます。
例
/**
* 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(fileProperties)
指定したファイルを、ローカル コンピューターで指定された既定のダウンロード場所にダウンロードします。
export function downloadFile(fileProperties: DownloadFileProperties): void;
パラメーター
- fileProperties
- OfficeScript.DownloadFileProperties
ダウンロードするファイル。
スロー:DownloadFileNameMissing 名前が空の場合にスローされます。
スロー:DownloadFileContentMissing コンテンツが空の場合にスローされます。
スロー:DownloadFileInvalidExtension ファイル名拡張子が ".txt" または ".pdf" ではない場合にスローされます。
スロー:ExternalApiTimeout API がタイムアウト制限の 30 秒に達した場合にスローされます。
返品
void
例
/**
* 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.
// Download the PDF.
OfficeScript.downloadFile(pdfFile);
// 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.Metadata.getScriptName()
現在実行中のスクリプトの名前を取得します。
export function getScriptName(): string;
返品
string
例
/**
* This script gets the name of the current script and prints it to the console.
*/
function main(workbook: ExcelScript.Workbook) {
// Get the name of the currently running script.
const scriptName = OfficeScript.Metadata.getScriptName();
console.log("The currently running script is: " + scriptName);
OfficeScript.saveCopyAs(filename)
OneDrive 内の現在のブックのコピーを、指定されたファイル名で元のファイルと同じディレクトリに保存します。 この API は、他の API の前に呼び出す必要があります。
export function saveCopyAs(filename: string): void;
パラメーター
- filename
-
string
コピーして保存したファイルのファイル名。 ファイル名は ".xlsx" で終わる必要があります。
スロー:SaveCopyAsInvalidExtension ファイル名が ".xlsx" で終わらない場合にスローされます。
スロー:SaveCopyAsMustBeCalledFirst このメソッドが他の API の後に呼び出された場合にスローされます。
スロー:SaveCopyAsFileMayAlreadyExist コピーのファイル名が既に存在する場合はスローされます。
スロー:SaveCopyAsInvalidCharacters ファイル名に無効な文字が含まれている場合はスローされます。
スロー:SaveCopyAsFileNotOnOneDrive ドキュメントが OneDrive に保存されていない場合にスローされます。
スロー:ExternalApiTimeout API がタイムアウト制限の 30 秒に達した場合にスローされます。 コピーは引き続き作成される可能性があることに注意してください。
返品
void
例
/**
* This script saves a copy of the current workbook to the user's OneDrive.
*/
function main(workbook: ExcelScript.Workbook) {
OfficeScript.saveCopyAs("CopyOfBook2.xlsx");
}
OfficeScript.sendMail(mailProperties)
Office スクリプトを使用してメールを送信します。
MailProperties を使用して、メールの内容と受信者を指定します。
export function sendMail(mailProperties: MailProperties): void;
パラメーター
- mailProperties
- OfficeScript.MailProperties
返品
void
例
/**
* 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]
})
}