通过python读取Docx文件
有人知道python库可以读取docx文件吗通过python读取Docx文件,python,docx,python-docx,Python,Docx,Python Docx,有人知道python库可以读取docx文件吗 我有一个word文档,我正试图从中读取数据。快速打开该包。python docx既可以读取也可以写入 doc = docx.Document('myfile.docx') allText = [] for docpara in doc.paragraphs: allText.append(docpara.text) 现在所有段落都将在列表allText中 多亏了阿尔·斯维加特为指针写的“如何用Python自动化无聊的东西” import d
我有一个word文档,我正试图从中读取数据。快速打开该包。python docx既可以读取也可以写入
doc = docx.Document('myfile.docx')
allText = []
for docpara in doc.paragraphs:
allText.append(docpara.text)
现在所有段落都将在列表allText中
多亏了阿尔·斯维加特为指针写的“如何用Python自动化无聊的东西”
import docx
def main():
try:
doc = docx.Document('test.docx') # Creating word reader object.
data = ""
fullText = []
for para in doc.paragraphs:
fullText.append(para.text)
data = '\n'.join(fullText)
print(data)
except IOError:
print('There was an error opening the file!')
return
if __name__ == '__main__':
main()
别忘了使用(pip install python docx)安装python docx我会使用
python docx
它不是用来写东西的吗?不用于读取您想从docx文件中获取哪些信息?只是发短信?图像?元数据?它只是文本,但格式与文档相同。另一种方法是使用libreoffice命令行将.docx
转换为.odt
,然后检查.odt
文件。AFAIK odt python工具比docx好。我知道docx包,它是用于编写而不是阅读的:/