Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 428
Idan Cohen Avatar asked Dec 06 '17 16:12

Idan Cohen


1 Answers

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")
like image 160
Allanrbo Avatar answered Jan 03 '23 16:01

Allanrbo