我在python上有结构化的文本。我想将其保存到docx文件。
类似
text = "A simple text\n Structured"
with open('docx_file.docx', 'w') as f:
f.write(text)
docx文件不是纯文本文件,因此,除非您不想为此使用库,否则我建议https://grokonez.com/python/how-to-read-write-word-docx-files-in-python-docx-module。
检查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)