我有一个关于 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)
检查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)