0

我正在尝试将名称设置为 Excel 表(我使用下面的代码创建)以替换默认表

    with pd.ExcelWriter('pandas_table.xlsx', engine='xlsxwriter') as writer:
        df.to_excel(writer, sheet_name='StgFull', startrow=1, header=False, index=False)
        workbook = writer.book
        worksheet = writer.sheets['StgFull']
        (max_row, max_col) = df.shape
        tabname = 'abcd'
        column_settings = [{'header': column} for column in df.columns]
        worksheet.add_table(0, 0, max_row, max_col - 1
                            , {'columns': column_settings}
                            )
        worksheet.set_column(0, max_col - 1, 12)
    writer.save()

在此处输入图像描述

4

1 回答 1

1

好吧,我不得不这样做:

worksheet.add_table(0, 0, max_row, max_col - 1
                            , {'columns': column_settings
                            ,"name": "TabName"}
                            )
于 2020-11-18T19:54:05.040 回答