'How to cancel auto filter on table with openpyxl

The title said it all :)

But still, I'm using the class Table from openpyxl.worksheet.table to define a table in excel file which I create. My problem is that the table that is created has Filter on the first row that I want to remove (from the script, not by opening the Excel file).

This is the calling for Table class:

tab = Table(displayName='Table_{}'.format(table_name.replace(' ', '_')),
                                          ref="{}:{}".format(table_start, table_end))

This is what I get:

enter image description here

This is what I want to get:

enter image description here

I search for it at OpenPyXL Docs but find only adding that filtering...

There is any way to remove this?

Many thanks!



Solution 1:[1]

wb = load_workbook(filename="data.xlsx")
ws = wb["Sheet1"]
ws.auto_filter.ref = None
for i in range(2, ws.max_row + 1):
    ws.row_dimensions[i].hidden = False
wb.save("data.xlsx")

Solution 2:[2]

I just ran across this and here is how I solved it.

#Opens the file
wb = load_workbook(filename = 'somefile')

#Set worksheet
ws = wb['sheetname'] # Tab name

#set table
tbl = ws.tables["tablename"]

#removes all filters 
tbl.autoFilter.filterColumn.clear()

Solution 3:[3]

helo,

tab = Table( displayName='Table_{}'.format(table_name.replace(' ', '_'))
       , ref="{}:{}".format(table_start, table_end)
       , headerRowCount = 0 # default is 1
       )

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Allanrbo
Solution 2 drweaze
Solution 3 Guy_NYAMSI