1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| 复制import xlsxwriter
WenJian = xlsxwriter.Workbook('data.xlsx') # 创建sheet sheet = WenJian.add_worksheet('newsheet') # 写入 sheet.write(0, 0, '2020年底') sheet.merge_range(1, 0, 2, 2, '第一节度销售统计') # 合并单元格写入数据 data = ( ('一月份', 200, 300, 400), ('二月份', 200, 300, 400), ('三月份', 200, 300, 400), ('四月份', 200, 300, 400), ) # 从第4行第1列,横向写入数据 sheet.write_row(3,0, ['月份','预期销售额','实际销售额']) # 循环写入 for index,item in enumerate(data): sheet.write_row(index+4,0,item) # 写入Excel公式 sheet.write(7,1,"=sum(B5:B7)") sheet.write(8,2,"=sum(B5:B7)") # 写入超链接 sheet.write_url(9,0,"http://xiaozhou.top", string='更多数据') # 写入图片 sheet.insert_image(10,0,'图片.png') # 关闭 WenJian.close()
|