提取多个word中的表格信息填入不同Excel的sheet
提取多个word中表格内容到Excel。
提取一个word文件到Excel的不同sheet已经能跑,目前卡在用glob读取文件夹下word中的表格。
不同sheet是word表格中的不同信息。
报错显示:name ‘tables’ is not defined
doc_ls=[]
dic1={}
for path in glob.glob('文件夹\*.docx'):
doc = Document(path)
for table in doc.tables:
for i, row in enumerate(table.rows[1:7]):
row_content = []
for cell in row.cells[:]:
c = cell.text
row_content.append(c)
print (row_content)
table = tables[0]
finaldict1 = {}
n = 5
for i, row in enumerate(table.rows[n:n+1]):
row_content = []
for cell in row.cells[1:6]:
c = cell.text
row_content.append(c)
allcol = row_content
for c in allcol:
finaldict1[c] = []
n += 1
python小白。
代码格式错误, 缩格不对, 请参考以下内容, 再重新编辑内容.
代码高亮
glob
andDocument
tables
before you use it intable = tables[0]
?用 glob 读取文件夹下 word 中的表格没问题啊 ! 不清楚你后面的代码是作什么 ?!
以下是我提供的代码
Not checked if it work or correct.