[英]Read from a word file in python
如何從 python 中的單詞(docx)文件中讀取。 我可以從 txt 文件中讀取,但不能對 MS Office word 文檔執行相同的操作。 有什么建議么?
有幾個包可以讓你做到這一點。 查看
import docx2txt
# extract text
text = docx2txt.process("file.docx")
# extract text and write images in /tmp/img_dir
text = docx2txt.process("file.docx", "/tmp/img_dir")
請參閱允許讀取 docx 文件的此庫https://python-docx.readthedocs.io/en/latest/
您應該使用 PyPi 上可用的 python-docx 庫。 然后你可以使用以下
doc = docx.Document('myfile.docx')
allText = []
for docpara in doc.paragraphs:
allText.append(docpara.text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.