OfficeScript package

インターフェイス

OfficeScript.DownloadFileProperties

ダウンロードするファイル。

OfficeScript.EmailAttachment

メールと共に送信する添付ファイル。 to cc、または bcc パラメーターの少なくとも 1 つに対して値を指定する必要があります。 受信者が指定されていない場合は、次のエラーが表示されます。"メッセージに受信者がいません。 "to"、"cc"、または "bcc" パラメーターのうち少なくとも 1 つの値を入力してください。

OfficeScript.MailProperties

送信するメールのプロパティ。

列挙型

OfficeScript.EmailContentType

コンテンツの種類。 指定可能な値は、テキストまたは HTML です。

OfficeScript.EmailImportance

電子メールの重要度値。 Outlook UI で使用できる重要度値 "high"、"normal"、"low" に対応します。

関数

OfficeScript.convertToPdf()

ドキュメントを PDF に変換し、そのテキスト エンコーディングを返します。

OfficeScript.downloadFile(fileProperties)

指定したファイルを、ローカル コンピューターで指定された既定のダウンロード場所にダウンロードします。

OfficeScript.Metadata.getScriptName()

現在実行中のスクリプトの名前を取得します。

OfficeScript.saveCopyAs(filename)

OneDrive 内の現在のブックのコピーを、指定されたファイル名で元のファイルと同じディレクトリに保存します。 この API は、他の API の前に呼び出す必要があります。

OfficeScript.sendMail(mailProperties)

Office スクリプトを使用してメールを送信します。 MailProperties を使用して、メールの内容と受信者を指定します。

関数の詳細

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;

パラメーター

返品

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]
    })
 }