简体   繁体   English

尽管文件不仅仅是换行符,但从 .docx 文件读取会产生换行符

[英]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:我在.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.

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文件的支持是否如此有限,以至于可能会被文件行上较小的字体大小所迷惑?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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