Skip to content

Conversation

@antznette1
Copy link

@antznette1 antznette1 commented Oct 30, 2025

@rhshadrach

Adds an autofilter parameter to DataFrame.to_excel() to enable Excel autofilter
over the header row and data range when writing files.

Usage:

df.to_excel("output.xlsx", autofilter=True)

Supports xlsxwriter and openpyxl engines. When autofilter=True, applies an
autofilter over the written data range (header row through last data row).

Closes #62651

@antznette1
Copy link
Author

Hi @rhshadrach, I hope you’re doing well.
When you get a chance, could you please review my PR? I’d really appreciate your feedback so we can move it forward.
Thanks a lot!

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I think this is looking good. Unfortunately it seems that odfpy does not provide a reasonable way to add an autofilter. If that is the case, I think we should raise when autofilter=True is passed and this engine is used. Can you add this and a test.

Can you also add tests for:

  • nonzero startrow / startcol
  • A DataFrame with MultiIndex columns (also called a hierarchical index) with both merge_cells=True and merge_cells=False.

@antznette1
Copy link
Author

Thanks for the PR! I think this is looking good. Unfortunately it seems that odfpy does not provide a reasonable way to add an autofilter. If that is the case, I think we should raise when autofilter=True is passed and this engine is used. Can you add this and a test.

Can you also add tests for:

  • nonzero startrow / startcol
  • A DataFrame with MultiIndex columns (also called a hierarchical index) with both merge_cells=True and merge_cells=False.

Okay, Im working on them now

@antznette1
Copy link
Author

Hi @rhshadrach .
Could you please review my PR when you are chanced?

…ge for xlsxwriter/openpyxl; keep engine_kwargs semantics intact
- Remove duplicate to_excel function code in generic.py
- Add NotImplementedError for odfpy engine when autofilter=True
- Remove broad exception handling from autofilter implementations
- Add comprehensive tests for nonzero startrow/startcol
- Add tests for MultiIndex columns with merge_cells=True and False
- Improve tests to verify each column has autofilter
- Remove redundant test_to_excel test
- Remove redundant pytest.importorskip from test functions
…port

- Keep ExcelWriter and ExcelFormatter in TYPE_CHECKING for type hints
- Import both at runtime inside to_excel method to avoid circular import
@rhshadrach
Copy link
Member

@antznette1 - tests are failing, are you able to run them locally?

Also I want to mention #62994 is looking to add the same feature and appears close to being ready.

@antznette1
Copy link
Author

@antznette1 - tests are failing, are you able to run them locally?

Also I want to mention #62994 is looking to add the same feature and appears close to being ready.

Yes, I can run locally. I realized my branch currently adds tests that assert behavior for an API not on main yet (and I left some debug prints). I’m cleaning that up now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: : Add header Autofilter and optional bold via engine_kwargs in to_excel

2 participants