python提取word表格的操作相对简单,但是有时候我们会遇到提取的是嵌套表格的情况,这需要一点技巧,本文就分享一个简单的案例
需要提取的表格中嵌套了子表格
大概就是上面的样子,处理结果是嵌套的子表格,并且右边的具体内容又是一个嵌套的表格
处理代码如下
from docx import Document
import xlsxwriter
#设置文件的目录
path="投诉件.docx"
# 存储我们刚刚读出来的数据
dict = {}
# 解析传入的文件,将信息填入dict
def getdict(path):
wordfile = Document(path)
# 遍历每一行
for i in range(len(wordfile.tables[1].rows)):
for j in range(len(wordfile.tables[1].rows[i].cells)):
#print(str(i) + " " + str(j) + " " + wordfile.tables[1].rows[i].cells[j].text)
if(i==5 and j==1):
dict["来电内容"] = wordfile.tables[1].rows[i].cells[j].text
elif(i==8 and j==3):