2309ddocx02文档

风格,页眉和页脚等内容与主要分开,允许在起始文档中放大量自定义,然后在生成文档中显示.

打开文档

from docx import Document
document = Document()
document.save("test.docx")

真正打开文档

要用文件名打开文档:

document = Document("existing-document-file.docx")
document.save("new-file-name.docx")

打开"类似文件"文档

f = open("foobar.docx", "rb")
document = Document(f)
f.close()
//或
with open("foobar.docx", "rb") as f:
    source_stream = StringIO(f.read())
document = Document(source_stream)
source_stream.close()
...
target_stream = StringIO()
document.save(target_stream)

猜你喜欢

转载自blog.csdn.net/fqbqrr/article/details/132684424
今日推荐