Extract data from multiple word tables and write them into the same sheet in Excel.
path = 'folder path'
worddocs_list = []
for filename in os.listdir(path):
wordDoc = Document(path+'\\'+filename)
worddocs_list.append(wordDoc)
writer = pd.ExcelWriter("./test.xlsx", engine='xlsxwriter')
i = 0
for wordDoc in worddocs_list:
for table in wordDoc.tables:
lst = []
for row in table.rows[5:6]:
row_lst = []
for cell in row.cells[1:7]:
c = cell.text
row_lst.append(c)
lst.append(row_lst)
df = pd.DataFrame()
N = 6
split_list = np.array_split(lst, N, axis=0)
for i in range(N):
df.loc[0, 'Column_{}'.format(i)] = split_list[0][0][i]
print(df)
df.to_excel(writer, sheet_name=f'Sheet{1}')
i += 1
writer.save()
In the TEST file, only the content of the last loop. How to write βROW+1β in each loop, thank you!!