终于把下载excell的接口弄好了!
@classmethod
def _write_excel(cls,difficulties_df):
"""
输出excel文件到io中
:return:
"""
output= io.BytesIO()
# writer = pd.ExcelWriter('销售周报.xlsx', engine='xlsxwriter', options={'nan_inf_to_errors': False})
writer= xlsxwriter.Workbook(output)
sheet= writer.add_worksheet('销售周报')
hasIndex = True
alphabet = ['ABCDEFGHIJKLMNOPQRSTUVWXYZ']
n_levels= difficulties_df.columns.nlevels
# header
for i_rowin range(n_levels):
for i_col, valin enumerate(difficulties_df.columns.get_level_values(i_row)):
sheet.write(i_row, i_col, val)
# value
for i_row, rowin enumerate(difficulties_df.itertuples(index=False), n_levels):
for i_col, valin enumerate(row):
sheet.write(i_row, i_col, val)
# difficulties_df.to_excel(writer,index=hasIndex) # startcol=1,index=False
merge_format= writer.add_format({
'bold': True,
'align': 'center',# 水平居中
'valign': 'vcenter',# 垂直居中
})
sheet.merge_range('A1:H1','项目信息',merge_format)
sheet.merge_range('I1:J1','当前瓶颈',merge_format)
sheet.merge_range('K1:N1','突破策略',merge_format)
writer.close()
output.seek(0)
return output
1commit,push到gitlab
2
网友评论