0

I currently have a file with data that looks like this.

enter image description here

I am trying to get it to look like this.

enter image description here

All I need is the filter added. I need to have this filter created in Python but I am not sure how. I do not need to go through Pandas and I have tried openpyxl. My caveat is that I am not currently filtering anything. I just need the filter to be present for others to use.

5
  • yeah, and like I mentioned, I just need the filter. I tried using the open pyxl filter and it gives me an error because the value must be a sequence. However, I am not trying to filter at this time, simply having the filter. Commented Nov 7, 2022 at 17:12
  • the link @sunnytown sent, just shows me how I can filter certain words/items. That is not what I need done here. I am simply trying to create the filter here without having to have existing words/items to filter. This way, when someone else goes into the workbook they can do that themself. Commented Nov 7, 2022 at 17:14
  • As the page says, Openpyxl cannot be used to perform the actual filtering operation but just to setup the filter. Also, if you get a specific error, feel free to post your code so that you can get some actual help. Commented Nov 7, 2022 at 17:14
  • You were right @sunnytown, my apologies. I must have missed that in the documentation portion. It works now! Very much appreciated. I will go ahead and post my solution Commented Nov 7, 2022 at 17:22
  • Glad it worked out. Sorry for my passive aggressive tone though. Commented Nov 7, 2022 at 17:54

1 Answer 1

1

For the solution, I followed openpyxl's documentation and used this to create a filter by Batch Number.

ws.auto_filter.ref = 'A:A'
ws.auto_filter.add_filter_column(0,["Batch IDS"])

This worked for me! Hope it helps someone else. Openpyxl does not filter for you just creates the filter

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.