Skip to content

Conversation

@jarent-nvidia
Copy link
Contributor

@jarent-nvidia jarent-nvidia commented Nov 5, 2025

Description of the change:
Added boolean 'autofilter' optional argument to 'DataFrame.to_excel' function to add automatic filters to all columns in the exported excel files. As discussed with @WillAyd starting simple by allowing to add filters only to all or none columns.
New option supported by 'xlsxwriter' and 'openpyxl' engines.

@jarent-nvidia jarent-nvidia marked this pull request as draft November 5, 2025 18:14
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Small comment but overall looks like a really nice PR. @rhshadrach any thoughts?

@jarent-nvidia jarent-nvidia marked this pull request as ready for review November 5, 2025 21:19
ws = wb.active

assert ws.auto_filter.ref is not None
print(ws.auto_filter.ref)
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the print statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Print statement removed - thanks for checking!

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm - let's see what others think

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.

Agreed this is looking very good. Can you add tests for:

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

startrow: int = 0,
startcol: int = 0,
freeze_panes: tuple[int, int] | None = None,
autofilter_range: str | None = None,
Copy link
Member

Choose a reason for hiding this comment

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

It seems to me we should be raising an error here if a user specifies autofilter=True and it is not supported with an engine rather than silently ignore the user's specification.

jarent-nvidia and others added 3 commits November 12, 2025 00:26
feat: Throw an error when autofilter set for 'odf' engine.
feat: Shows warning when autofilter is set together with merge_cells.
chore: Added tests for index=True, startrow/startcol, multindex with merge_cells.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement IO Excel read_excel, to_excel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: adding a filter (and bold) to header when writing to excel

3 participants