共用方式為


HOW TO:列印文件

更新:2007 年 11 月

適用於

本主題中的資訊僅適用於指定的 Visual Studio Tools for Office 專案和 Microsoft Office 版本。

專案類型

  • 文件層級專案

  • 應用程式層級專案

Microsoft Office 版本

  • Word 2003

  • Word 2007

如需詳細資訊,請參閱依應用程式和專案類型提供的功能

您可以列印整份 Microsoft Office Word 文件或部分文件。

列印屬於文件層級自訂一部分的文件

若要列印整份文件

  • 呼叫 Microsoft.Office.Tools.Word.Document 類別的 PrintOut 方法以列印整份文件。若要使用這個範例,請從專案中的 ThisDocument 類別中執行程式碼。

    Me.PrintOut()
    
    object copies = "1";
    object pages = "";
    object range = Word.WdPrintOutRange.wdPrintAllDocument;
    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
    object pageType = Word.WdPrintOutPages.wdPrintAllPages;
    object oTrue = true;
    object oFalse = false;
    
    this.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue, 
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    

若要列印文件的目前頁面

  • 呼叫 Microsoft.Office.Tools.Word.Document 類別的 PrintOut 方法,並指定要列印一份目前的頁面。若要使用這個範例,請從專案中的 ThisDocument 類別中執行程式碼。

    Me.PrintOut( _
        Background:=True, _
        Append:=False, _
        Range:=Word.WdPrintOutRange.wdPrintCurrentPage, _
        Item:=Word.WdPrintOutItem.wdPrintDocumentContent, _
        Copies:="1", _
        Pages:="1", _
        PageType:=Word.WdPrintOutPages.wdPrintAllPages, _
        PrintToFile:=False, _
        Collate:=True, _
        ManualDuplexPrint:=False)
    
    object copies = "1"; 
    object pages = "1"; 
    object range = Word.WdPrintOutRange.wdPrintCurrentPage; 
    object items = Word.WdPrintOutItem.wdPrintDocumentContent; 
    object pageType = Word.WdPrintOutPages.wdPrintAllPages; 
    object oTrue = true; 
    object oFalse = false; 
    
    this.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue, 
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    

使用應用程式層級增益集列印文件

若要列印整份文件

  • 呼叫您想列印之 Microsoft.Office.Interop.Word.Document 物件的 PrintOut 方法。下列程式碼範例會列印現用文件。若要使用這個範例,請從專案中的 ThisAddIn 類別中執行程式碼。

    Me.Application.ActiveDocument.PrintOut()
    
    object copies = "1";
    object pages = "";
    object range = Word.WdPrintOutRange.wdPrintAllDocument;
    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
    object pageType = Word.WdPrintOutPages.wdPrintAllPages;
    object oTrue = true;
    object oFalse = false;
    
    this.Application.ActiveDocument.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    

若要列印文件的目前頁面

  • 呼叫您想列印之 Microsoft.Office.Interop.Word.Document 物件的 PrintOut 方法,並指定要列印一份目前的頁面。下列程式碼範例會列印現用文件。若要使用這個範例,請從專案中的 ThisAddIn 類別中執行程式碼。

    Me.Application.ActiveDocument.PrintOut( _
        Background:=True, _
        Append:=False, _
        Range:=Word.WdPrintOutRange.wdPrintCurrentPage, _
        Item:=Word.WdPrintOutItem.wdPrintDocumentContent, _
        Copies:="1", _
        Pages:="1", _
        PageType:=Word.WdPrintOutPages.wdPrintAllPages, _
        PrintToFile:=False, _
        Collate:=True, _
        ManualDuplexPrint:=False)
    
    object copies = "1";
    object pages = "1";
    object range = Word.WdPrintOutRange.wdPrintCurrentPage;
    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
    object pageType = Word.WdPrintOutPages.wdPrintAllPages;
    object oTrue = true;
    object oFalse = false;
    Word.Document document = this.Application.ActiveDocument;
    
    document.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    

請參閱

工作

HOW TO:在預覽列印中顯示文件

概念

了解 Office 方案中的選擇性參數