使用 win32com 打印 Word 文档的多个副本

2024-10-03 02:32:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个tkinter接口,它允许我打印Word文档的多个副本。对于这个am,使用win32com。在

from win32com import client
from tkinter import *
import time
import os

def printWordDocument(filename,NumPage1):
    word = client.Dispatch("Word.Application")

    path=str(os.path.realpath(__file__))
    path = path[:-16]
    filename=path+filename

    word.Documents.Open(filename)
    word.ActiveDocument.PrintOut(Copies=2,Collate=True)
    root.focus()
    time.sleep(10)
    word.ActiveDocument.Close()

    word.Quit()

root=Tk()
root.attributes("-fullscreen",True)
Button(root,text='Print',command=lambda:printWordDocument('PrintThis.docx',2)).pack()

root.mainloop()

当我按按钮打印文档时,它只打印一个副本,它忽略了赋予它的“副本”选项。在

有人知道它为什么这么做吗?在

另外,我也看过其他已经发布的问题,要么它们和我的问题不一样,要么没有答案。在


Tags: pathfrom文档importclienttimeostkinter