1

I'am trying to set a name to Excel table (that i created with the code below) in order to replace the default one

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

enter image description here

2
  • This help? xlsxwriter.readthedocs.io/working_with_tables.html Commented Nov 18, 2020 at 19:15
  • When i tried to add the parameter name, i've got an error : TypeError: add_table() takes from 5 to 6 positional arguments but 7 were given Commented Nov 18, 2020 at 19:20

1 Answer 1

2

Well, i had to do this :

worksheet.add_table(0, 0, max_row, max_col - 1
                            , {'columns': column_settings
                            ,"name": "TabName"}
                            )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.