[日常]用Python读取word文档中的表格并比较
最近想对某些word文档(docx)的表格内容作比较, 于是找了一下相关工具. 参考Automate the Boring Stuff with Python中的word部分, 试用了python-docx - python-docx 0.8.7 documentation 演示如下. 两个简单的word文档, 各有一个表格: 读取文档中的表格到列表(为演示只对单列表格操作): import docx def 取表格(文件名): 文件 = docx.Document(文件名) 首个表 = 文件.tables[0] 值 = [] for 行 in 首个表.rows: for 格 in 行.cells: 值.append(格.text) print(文件名 + " -> " + str(值)) return 值 表1 = 取表格('表1.docx') 读取结果: 表1.docx -> ['值1', '值2', '值3'] 接着找到这个做比较的python库seperman/deepdiff, 来源: Get difference between two lists from d...
