How to add column filters to Excel worksheet using XLWINGS

0 votes
My Python method for generating an Excel sheet is almost complete. One of the last things to do is to add a filtering option to the sheet's top row (using the Excel shortcut CTRL+SHIFT+L). No filtering should be done; just add the filter. Although I can open the file and complete the task manually, it would be wonderful if it could be automated.

Is it possible?
Dec 22, 2022 in Others by Kithuzzz
• 38,000 points
2,286 views

1 answer to this question.

0 votes

Call the API property to activate the autofilter:

import xlwings as xw

path = r"test.xlsx"

wb = xw.Book(path)
ws = wb.sheets[0]

ws.used_range.api.AutoFilter(Field:=1)

 You can also use native xlwings functions (create a table object and then set its show_autofilter to True):

import xlwings as xw

path = r"test.xlsx"

wb = xw.Book(path)
ws = wb.sheets[0]

ws.tables.add(ws.used_range, name="a_table")
ws.tables["a_table"].show_autofilter = True
# This way adds formatting in addition to the filter.
answered Dec 23, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer

How to split columns into two sub columns under their parent column using python in excel

Use str.split: df[['pre', 'post']] = df['Column A'].str.split(r'\s*-->\s*', expand=True) print(df) # Output ...READ MORE

answered Apr 7, 2023 in Others by Kithuzzz
• 38,000 points
1,920 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
1,053 views
0 votes
1 answer

How to convert data from txt files to Excel files using python

Hi , there are few steps to ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,690 points
14,026 views
0 votes
1 answer

How to print an Excel Sheet using VBA with Nitro PDF Creator in Excel 2016

you can use the built-in excel facilities ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 63,600 points
1,348 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

How to add meta keyword in wordpress using yoast seo plugin.?

if you dont want to use code ...READ MORE

answered Feb 12, 2022 in Others by narikkadan
• 63,600 points
999 views
0 votes
1 answer

How to add SEO properties in sitemap using xml

i think your layout of the sitemap ...READ MORE

answered Feb 12, 2022 in Others by narikkadan
• 63,600 points
830 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP