美文网首页
2019-07-30终于把下载excell的接口弄好了!

2019-07-30终于把下载excell的接口弄好了!

作者: 每日派森 | 来源:发表于2019-07-30 09:23 被阅读0次

    终于把下载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

    1

    commit,push到gitlab

    2

    相关文章

      网友评论

          本文标题:2019-07-30终于把下载excell的接口弄好了!

          本文链接:https://www.haomeiwen.com/subject/btfgrctx.html