def export_channel_loaned(queryset): today = time.strftime('%Y%m%d%H%M%S') excel_name = '%s_channel_loaned' % (today,) head_list = ['渠道', '合同金额', '合同件数', '逾期件数', '首期同期资产', 'M1逾期金额', 'M1逾期率', 'M1逾期率相比上周', '二期同期资产', 'M2逾期金额', 'M2逾期率', 'M2逾期率相比上周', '三期同期资产', 'M3逾期金额', 'M3逾期率', 'M3逾期率相比上周', '四期同期资产', 'M3+逾期金额', 'M3+逾期率', 'M3+逾期率相比上周'] export_excel = ExportExcel(excel_name) dct = export_excel.xxx(head_list) sheet_prd = dct['sheet_prd'][0] sheet_rpd=dct['sheet_prd'][1] #######################这里是重点 style_body = dct['style_body'] row = 1 if queryset: for content in queryset: sheet_prd.write(row, 0, content.name, style_body) sheet_prd.write(row, 1, str(content.contract_amount), style_body) sheet_prd.write(row, 2, utils.export_int2str_format(content.total), style_body) sheet_prd.write(row, 3, utils.export_int2str_format(content.overdue_total), style_body) sheet_prd.write(row, 4, str(content.first_contract_amount), style_body) sheet_prd.write(row, 5, str(content.m1_overdue_money), style_body) sheet_prd.write(row, 6, utils.format_float(content.m1_overdue_rate), style_body) sheet_prd.write(row, 7, str(utils.format_float(content.m1_overdue_rate_week_up)), style_body) sheet_prd.write(row, 8, str(content.second_contract_amount), style_body) sheet_prd.write(row, 9, str(content.m2_overdue_money), style_body) sheet_prd.write(row, 10, str(utils.format_float(content.m2_overdue_rate)), style_body) sheet_prd.write(row, 11, str(utils.format_float(content.m2_overdue_rate_week_up)), style_body) sheet_prd.write(row, 12, str(content.third_contract_amount), style_body) sheet_prd.write(row, 13, str(content.m3_overdue_money), style_body) sheet_prd.write(row, 14, str(utils.format_float(content.m3_overdue_rate)), style_body) sheet_prd.write(row, 15, str(utils.format_float(content.m3_overdue_rate_week_up)), style_body) sheet_prd.write(row, 16, str(content.fourth_contract_amount), style_body) sheet_prd.write(row, 17, str(content.m4_overdue_money), style_body) sheet_prd.write(row, 18, str(utils.format_float(content.m4_overdue_rate)), style_body) sheet_prd.write(row, 19, str(utils.format_float(content.m4_overdue_rate_week_up)), style_body) sheet_rpd.write(row,row-1,str(content.fourth_contract_amount), style_body) row += 1 return export_excel.x()
2,再加上sheet
def xxx(self, head_list): """ 形成表头 :param head_list: 表头数据 :return: """ sheet_prd = self.wb.add_sheet('PRD') sheet_rpd = self.wb.add_sheet('rpd') #######多设置一个sheet style_heading = xlwt.easyxf() style_body = xlwt.easyxf() style_body.num_format_str = self.fmts[0] j = 0 for i in head_list: sheet_prd.write(0, j, i, style_heading) sheet_rpd.write(0,j,i,style_heading) j += 1 return {'sheet_prd': [sheet_prd,sheet_rpd], 'style_body': style_body}