|
- from docx import Document
- import os
- path = 'f:/人员信息/'
- list1 = []
- for lujing,liebiao,wenjian in os.walk(path):
- for i in wenjian:
- url = lujing+i
- doc = Document(url)
- tables = doc.tables
- tb = tables[0]
- tb_rows = tb.rows
- row_data_name = []
- rows_cells = tb_rows[0].cells
- for cell in rows_cells:
- row_data_name.append(cell.text)
- name = row_data_name[2]
- print(name)
- row_date_xb = []
- rows_cells = tb_rows[0].cells
- for cell in rows_cells:
- row_date_xb.append(cell.text)
- xb = row_date_xb[6]
- print(xb)
- row_date_zy = []
- rows_cells = tb_rows[7].cells
- for cell in rows_cells:
- row_date_zy.append(cell.text)
- zy = row_date_zy[6]
- print(zy)
- row_date_zyt = []
- rows_cells = tb_rows[8].cells
- for cell in rows_cells:
- row_date_zyt.append(cell.text)
- zyt = row_date_zyt[4]
- print(zyt)
- row_data_tel = []
- rows_cells = tb_rows[2].cells
- for cell in rows_cells:
- row_data_tel.append(cell.text)
- tel = row_data_tel[-1]
- print(tel)
- row_data_name1 = []
- rows_cells = tb_rows[7].cells
- for cell in rows_cells:
- row_data_name1.append(cell.text)
- name1 = row_data_name1[2]
- print(name1)
- row_data_name2 = []
- rows_cells = tb_rows[10].cells
- for cell in rows_cells:
- row_data_name2.append(cell.text)
- name2 = row_data_name2[2]
- print(name2)
- list1.append([name,xb,tel,name2,name1,zy,zyt])
- print(list1)
- output = open('f:/人员信息/001.xls','w',encoding='gbk')
- output.write('受援人\t性别\t联系电话\t案件名称\t承办人姓名\t承办人执业单位\t承办人联系电话\n')
- for i in range(len(list1)):
- for j in range(len(list1[i])):
- output.write(str(list1[i][j]))
- output.write('\t')
- output.write('\n')
- output.close()
复制代码
|
|