共用方式為


以程式設計方式在列印預覽中顯示文件

如果您的方案會產生報告,您可能想要在 [預覽列印] 模式中向使用者顯示報告。

適用對象:本主題資訊適用於文件層級的專案和 Word 的 VSTO 增益集專案。 如需詳細資訊,請參閱依 Office 應用程式和專案類型提供的功能

文件層級自訂的程序

呼叫 PrintPreview 方法以在預覽列印中顯示文件

  1. 請呼叫 PrintPreview 類別的 Document 方法。 若要使用此程式碼範例,請從專案的 ThisDocument 類別中執行它。

    this.PrintPreview();
    

設定 PrintPreview 屬性以在預覽列印中顯示文件

  1. PrintPreview 物件的 Application 屬性設定為 true

    Application.PrintPreview = true;
    

VSTO 增益集的程序

呼叫 PrintPreview 方法以在預覽列印中顯示文件

  1. 呼叫您要預覽之 PrintPreviewDocument 方法。 若要使用此程式碼範例,請從專案的 ThisAddIn 類別中執行它。

    this.Application.ActiveDocument.PrintPreview();
    

設定 PrintPreview 屬性以在預覽列印中顯示文件

  1. PrintPreview 物件的 Application 屬性設定為 true

    Application.PrintPreview = true;