双面打印Word文档

2 投票
1 回答
1858 浏览
提问于 2025-04-17 21:25

我正在尝试自动化一个任务,就是把大约30个Word文档打印成双页的两份。我想把这个程序转换成.exe文件(我计划只在Windows电脑上使用),使用的是py2exe。我知道我可以手动设置打印选项,但在大约20台电脑上我无法这样做,而且我也不能在这些电脑上安装新的软件(这就是我想把它转换成.exe的原因)。

我复制了这个解决方案来进行打印,但我无法调整它来满足我的需求:

from win32com import client
import time

word = client.Dispatch("Word.Application")

filename=input("What files do you want to print?")

def printWordDocument(filename):
    """Given a name of a file prints it. TODO: Add double page."""

    word.Documents.Open(filename)
    word.ActiveDocument.PrintOut()
    time.sleep(2)
    word.ActiveDocument.Close()

    word.Quit()

我找不到任何选项可以自动双页打印,PrintOut方法中唯一的双页选项是ManualDuplexPrint,文档中说:“如果打印机没有双面打印设备,设置为True可以打印双面文档。”但我并不想让打印变得更简单,只是想打印所有的文档。而且我希望这个程序能在其他电脑上使用,而不需要修改Word文档(我并不创建这些文档)。

还有其他方法可以做到吗?或者有什么其他选项可以选择吗?

更新

我还不会用Visual Basic编程,但如果我能得到一个模板或一些提示,我想我能做出适合我需求的东西。

1 个回答

0

我做了一个宏,但这个宏只能在我自己的电脑上运行,不能在其他应该能运行的电脑上使用。

Sub Test()
'
' Test Macro
' Print in double page and 2 copies
'
    ActivePrinter = "Xerox WC 24 PCL"
    Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentWithMarkup, Copies:=2, Pages:="", PageType:= _
        wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
        PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
        PrintZoomPaperHeight:=0
End Sub

撰写回答