Udostępnij za pośrednictwem


Programowe drukowanie dokumentów

Do drukarki domyślnej można wydrukować cały dokument programu Microsoft Office Word lub część dokumentu.

Dotyczy: informacje w tym temacie dotyczą projektów na poziomie dokumentu i projektów dodatków VSTO dla programu Word. Aby uzyskać więcej informacji, zobacz Funkcje dostępne przez aplikacja pakietu Office lication i typ projektu.

Aby wydrukować cały dokument

  1. Wywołaj metodę PrintOutThisDocument klasy w projekcie, aby wydrukować cały dokument. Aby użyć tego przykładu ThisDocument , uruchom kod z klasy .

    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);
    

Aby wydrukować bieżącą stronę dokumentu

  1. Wywołaj metodę PrintOutThisDocument klasy w projekcie i określ, że zostanie wydrukowana jedna kopia bieżącej strony. Aby użyć tego przykładu ThisDocument , uruchom kod z klasy .

    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);
    

Aby wydrukować cały dokument

  1. Wywołaj metodę PrintOutDocument obiektu, który chcesz wydrukować. Poniższy przykład kodu wyświetla aktywny dokument. Aby użyć tego przykładu ThisAddIn , uruchom kod z klasy w projekcie.

    this.Application.ActiveDocument.PrintOut(true, false, Word.WdPrintOutRange.wdPrintAllDocument,
        Item: Word.WdPrintOutItem.wdPrintDocumentContent, Copies:"1", Pages:"", 
        PageType:Word.WdPrintOutPages.wdPrintAllPages, PrintToFile:false, Collate:true,
        ManualDuplexPrint:false);
    

Aby wydrukować bieżącą stronę dokumentu

  1. Wywołaj metodę PrintOutDocument obiektu, który chcesz wydrukować, i określ jedną kopię bieżącej strony. Poniższy przykład kodu wyświetla aktywny dokument. Aby użyć tego przykładu ThisAddIn , uruchom kod z klasy w projekcie.

    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);