Search code examples
pythonexcelxlwings

Python/xlwings set excel table style to "none"


I have exported a dataframe to Excel using xlwings and am trying to format it as a table. I want to apply the "None" style but can't figure out how to specify the "None."

This line works:

table = sheet.tables.add(source=sheet["A1"].expand(), name = 'TableName', table_style_name = "TableStyleLight1")

But instead of "TableStyleLight1" I want "None". I have tried "", '', 0, "None" and none of them work.


Solution

  • You can use .api to access the native object, and clear the formatting after creating the table:

    table = sheet.tables.add(source=ws.range('I20:N40'), name='UnformattedTable')
    sheet.api.ListObjects('UnformattedTable').TableStyle = ""  # Windows specific
    

    But as mentioned in the comments, it doesn't seem to be supported using tables.add directly. xlwings has a missing feature page with an example on using .api. Note the above example is for windows, the api for mac is slightly different.