来自 python32 的 Python 打印 [英] Python Printing from python32
问题描述
我无法让 Python 打印 word 文档.我想要做的是打开 Word 文档,打印并关闭它.我可以打开 Word 和 Word 文档:
I can't get Python to print a word doc. What I am trying to do is to open the Word document, print it and close it. I can open Word and the Word document:
import win32com.client
msword = win32com.client.Dispatch("Word.Application")
msword.Documents.Open("X:\Backoffice\Adam\checklist.docx")
msword.visible= True
我已经尝试过下一步打印
I have tried next to print
msword.activedocument.printout("X:\Backoffice\Adam\checklist.docx")
我收到打印输出无效"的错误提示.
I get the error of "print out not valid".
有人可以解释一下我如何从 Python 打印这个文件.我认为这可能就像改变打印输出"这个词一样简单.谢谢,我是 Python 新手.
Could someone shed some light on this how I can print this file from Python. I think it might be as simple as changing the word "printout". Thanks, I'm new to Python.
推荐答案
msword.ActiveDocument
为您提供当前活动文档.PrintOut
方法打印该文档:它不将文档文件名作为参数.
msword.ActiveDocument
gives you the current active document. The PrintOut
method prints that document: it doesn't take a document filename as a parameter.
来自 http://msdn.microsoft.com/en-us/library/aa220363(v=office.11).aspx:
expression.PrintOut(Background, Append, Range, OutputFileName, From, To, Item,
Copies, Pages, PageType, PrintToFile, Collate, FileName, ActivePrinterMacGX,
ManualDuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth,
PrintZoomPaperHeight)
特别是 Word 正在尝试将您的文件名用作布尔值 Background
,它可以设置为 True
以在后台打印.
Specifically Word is trying to use your filename as a boolean Background
which may be set True
to print in the background.
编辑:案例很重要,错误有点奇怪.msword.ActiveDocument.Printout()
应该打印它.msword.ActiveDocument.printout()
抛出错误,抱怨PrintOut"不是属性.
Edit:
Case matters and the error is a bit bizarre. msword.ActiveDocument.Printout()
should print it. msword.ActiveDocument.printout()
throws an error complaining that 'PrintOut' is not a property.
我认为内部发生的事情是,当您在属性上不匹配大小写时,Python 会尝试进行补偿,但它并没有完全适合方法.或者类似的东西.ActiveDocument
和 activedocument
可以互换,但 PrintOut
和 printout
不是.
I think what happens internally is that Python tries to compensate when you don't match the case on properties but it doesn't get it quite right for methods. Or something like that anyway. ActiveDocument
and activedocument
are interchangeable but PrintOut
and printout
aren't.
这篇关于来自 python32 的 Python 打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!