将文本保存到 docx 文件 python

Asd*_*dfg 2 python docx

我有一个关于 python 的结构化文本。我想将其保存为 docx 文件。

就像是

text = "A simple text\n Structured"

with open('docx_file.docx', 'w') as f:
    f.write(text)
Run Code Online (Sandbox Code Playgroud)

pmo*_*mod 8

检查python-docx包:

from docx import Document

document = Document()
document.add_heading('A simple text', level=1)
document.add_paragraph('some more text ... ')

document.save('docx_file.docx')
Run Code Online (Sandbox Code Playgroud)