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.
Drukowanie dokumentu będącego częścią dostosowywania na poziomie dokumentu
Aby wydrukować cały dokument
Wywołaj metodę PrintOut
ThisDocument
klasy w projekcie, aby wydrukować cały dokument. Aby użyć tego przykładuThisDocument
, 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
Wywołaj metodę PrintOut
ThisDocument
klasy w projekcie i określ, że zostanie wydrukowana jedna kopia bieżącej strony. Aby użyć tego przykładuThisDocument
, 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);
Drukowanie dokumentu przy użyciu dodatku VSTO
Aby wydrukować cały dokument
Wywołaj metodę PrintOut Document 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.
Aby wydrukować bieżącą stronę dokumentu
Wywołaj metodę PrintOut Document 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);