失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python读取word文档表格里的数据

python读取word文档表格里的数据

时间:2022-10-30 23:40:47

相关推荐

python读取word文档表格里的数据

首先需要安装相应的支持库:

直接在命令行执行pip install python-docx

示例代码如下:

import docxfrom docx import Document #导入库path = "E:\\python_data\\1234.docx" #文件路径document = Document(path) #读入文件tables = document.tables #获取文件中的表格集table = tables[0 ]#获取文件中的第一个表格for i in range(1,len(table.rows)):#从表格第二行开始循环读取表格数据result = table.cell(i,0).text + "" +table.cell(i,1).text+table.cell(i,2).text + table.cell(i,3).text#cell(i,0)表示第(i+1)行第1列数据,以此类推print(result)

如果觉得《python读取word文档表格里的数据》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。