How to convert this code to get output in excel?
with open('table.csv', 'w', encoding='utf-8') as csvfile:
wr = csv.writer(csvfile)
for table in extracted_document['tables']:
for row in table['rows']:
wr.writerow([cell['content'] for cell in row['cells']])
I am using this code to get output in cvs file but now i want to write in excel..how to change this code to get output in excel? please help me
最佳答案
您可以使用 xlwt 模块。
import xlwt
wb = xlwt.Workbook()
ws = wb.add_sheet('sheet1')
for table in extracted_document['tables']:
for row_cnt, row in enumerate(table['rows']):
for col_cnt, c in enumerate([cell['content'] for cell in row['cells']]):
ws.write(row_cnt, col_cnt, c)
wb.save('table.xls')
关于python - 想要更改此代码以使用 python3 在 Excel 中编写吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55273603/