We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
The community reviewed whether to reopen this question 2 years ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
使用 Python 创建 Word 文档的方法有多种:
pywin32
)创建文档。 http://python.net/crew/pirx/spam7/编辑:
由于 COM 已超出问题,我建议如下(受到 @kcrumley 的回答的启发):
使用 UNO 库从 python 自动化 Open Office,在 OOWriter 中打开 HTML 文件,然后另存为 .doc。
EDIT2:
现在有一个纯Python python-docx 项目 看起来不错(我有没用过)。
A couple ways you can create Word documents using Python:
pywin32
). http://python.net/crew/pirx/spam7/EDIT:
Since COM is out of the question, I suggest the following (inspired by @kcrumley's answer):
Using the UNO library to automate Open Office from python, open the HTML file in OOWriter, then save as .doc.
EDIT2:
There is now a pure Python python-docx project that looks nice (I have not used it).
我尝试了 python-docx 并取得了成功,它使您能够在 Python 中制作和编辑 docx
I tried python-docx with succes, it enables you to make and edit docx within Python
1) 如果您想在当前流程的末尾再进行一步,现在有多种选项可用于将 PDF 文件转换为 Word 文件。 我还没有尝试过 123PDFConverter ,但 CNET 编辑推荐它(相同的链接); 它有免费试用版; 并且它支持自动化。 与任何第 3 方文件转换器一样,您的效果可能会有所不同,具体取决于您的 PDF 的复杂程度以及软件的实际性能。
2) 基于codeape的COM自动化建议,如果您COM自动化Word,您可以在Word中打开实际的HTML文件,并调用“另存为”命令,将其另存为DOC文件。
1) If you want to just stick another step on the end of your current pipeline, there are several options out there now for converting PDF files to Word files. I haven't tried 123PDFConverter, but the CNET Editors recommend it (same link); it has a free trial; and it supports automation. As with any 3rd-party file converter, your mileage may vary, depending how complicated your PDFs are, and how good the software actually is.
2) Building on codeape's COM automation suggestion, if you COM automate Word, you can open your actual HTML file in Word, and call the "Save As" command, to save it as a DOC file.
我也不得不用 python 做类似的事情。 这是比我想要的更多的手动工作,但使用 pyRTF 创建的文档导致 Word 和 OpenOffice 崩溃,我没有动力去尝试解决这个问题。
我发现创建具有我想要的样式的 Word 文档模板是最简单的(但并不理想)。 然后我的 Python 创建一个 HTML 文件,其
样式标记在 Word 样式之后。 然后我在 Word 中打开 HTML 文件并在 Word 中打开模板。 我将 HTML 文件中的所有文本剪切并粘贴到模板中,Word 会根据我之前设置的样式重新格式化所有文本。 这适用于我的情况下的偶尔文件。 它可能不适合您的情况。 供参考。
I have had to do something similar with python as well. It is far more manual work than I want, but documents created with pyRTF were causing Word and OpenOffice to crash and I didn't have the motivation to try to figure it out.
I have found it simplest (but not ideal) to create a Word document template with the styles I want. Then my Python creates an HTML file whose
<p>
styles are labeled after the Word styles. Then I open the HTML file in Word and open the template in Word. I cut and paste all text from the HTML file into the template, and Word re-formats it all according to the styles I had set up previously. That works for the occasional file in my situation. It might not work for your situation. FYI.您可以将其编写为 WordML XML 文件并将其压缩为 .docx 格式吗? 如果您的客户尚未使用 Office 2007,那么他们所需要的只是 Word 2007 筛选器。
那里有很多例子。
从 2003 年开始,您还可以将 XML 直接加载到 Word 中,或者 所以有人告诉我。
Can you write is as the WordML XML files and zip it up into the .docx format? All your client would need is the Word 2007 filter if they aren't on Office 2007 already.
There are many examples out there.
You can also load XML directly into Word, starting with 2003, or so I've been told.