将名称设置为 Excel Table 和 Python

Set a name to Excel Table with Python

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

    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()

嗯,我不得不这样做 :

worksheet.add_table(0, 0, max_row, max_col - 1
                            , {'columns': column_settings
                            ,"name": "TabName"}
                            )