import xlsxwriter wb=xlsxwriter.Workbook('data.xlsx') cell_format=wb.add_format({'bold':True}) cell_format1=wb.add_format() cell_format1.set_bold() cell_format1.set_font_color('red') cell_format1.set_font_size(14) cell_format1.set_align('center') cell_format2=wb.add_format() cell_format2.set_bg_color("#808080") #创建sheet sheet=wb.add_worksheet('sheet1') #写入 sheet.write(0,0,'2020年度',cell_format) sheet.merge_range(1,0,2,2,'第一季度',cell_format1) data=( ['一月份',500,450], ['二月份',600,650], ['三月份',700,550] ) sheet.write_row(3,0,['月份','预期销售额','实际的销售额'],cell_format2) for index,item in enumerate(data): sheet.write_row(index+4,0,item) #写入excel公式 sheet.write(7,1,'=sum(B5:B7)') sheet.write(7,2,'=sum(C5:C7)') sheet.write_url(9,0,'http://www.baidu.com',string='更多数据') sheet.insert_image(10,0,'view.png') wb.close()