【发布时间】:2021-12-09 20:33:25
【问题描述】:
我有一些文本存储在.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 文件的支持是否如此有限,以至于会被文件行上较小的字体大小混淆?
【问题讨论】:
-
如果文本在表格中,即使是没有边框的表格,paragraph.text 也不会得到它。尝试遍历 template.tables。
-
@CodeMonkey 表中没有数据。
-
检查修订状态。
python-docx不会在未接受的修订中选择段落。使用print(template._element)查看 XML 并查看是否有任何元素正在“包装”段落。
标签: python file python-docx paragraph