简体   繁体   中英

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

I have some text stored in a .docx file:

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.

Now when I try to read text from it:

import docx

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

The result is just a newline! Is the support for .docx files so limited it can be confused by the smaller font size on the file line?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM