'Formatting xlwings view output

I am using xlwings to write a dataframe to an excel sheet. Nothing special, and all works perfectly.

   xw.view(
       dataframe,
       abook.sheets.add(after = abook.sheets[-1]),
       table=True
   )

My issue is that the output excel sheet has filters in the top two rows, which I have to manually disable (by selecting the rows and clearning contents).

Thanks to https://github.com/xlwings/xlwings/issues/679#issuecomment-369138719

I changed my code to the following:

abook = xw.books.active
xw.view(
   dataframe,
   abook.sheets.add(after = abook.sheets[-1]),
   table=True
)
sheetname = abook.active.name
if wb.sheets[sheetname].api.AutoFilterMode == True:
      wb.sheets[sheetname].api.AutoFilterMode = False

which looked promising, but it didn't resolve my issue.

sample sheet header

I would appreciate any pointers, how I can have the filters turned off by default. I am using the latest xlwings on win 10, 11.

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source