从 .docx 文件中读取会产生一个换行符,尽管该文件不仅仅是一个换行符

Reading from .docx file results in a newline though the file is not just a newline

我在 .docx 文件中存储了一些文本:

Dear xx01xx,

    Thank you for coming to my birthday party. I’m glad you came. Thanks for the xx02xx present!

            Your best friend,
                Alan Bagel

If you want to see my token of appreciation for your coming, please go to xx03xx street.

现在,当我尝试从中读取文本时:

import docx

template = docx.Document("...")
for paragraph in template.paragraphs:
    print(paragraph.text)

结果只是换行!对 .docx 文件的支持是否如此有限以至于可能会被文件行上较小的字体混淆?

问题是即使您创建了一个 .docx 文件,您也忘记了保存它,因此 python-docx 无法读取它。