Working with Documents

Opening a document

from docx import Document

document = Document()
document.save('test.docx')

REALLY opening a document

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

Opening a ‘file-like’ document

f = open('foobar.docx', 'rb')
document = Document(f)
f.close()

# or

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)
上一篇:Spring实战(中文4,5版) PDF含源码


下一篇:On branch master nothing to commit, working tree clean ERROR: Repository not found. fatal: Could not