-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
ENH: adding autofilter when writing to excel (pandas-dev#61194) #62994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WillAyd
left a comment
There was a problem hiding this 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?
pandas/tests/io/excel/test_style.py
Outdated
| ws = wb.active | ||
|
|
||
| assert ws.auto_filter.ref is not None | ||
| print(ws.auto_filter.ref) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
WillAyd
left a comment
There was a problem hiding this 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
There was a problem hiding this 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=Trueandmerge_cells=False.
| startrow: int = 0, | ||
| startcol: int = 0, | ||
| freeze_panes: tuple[int, int] | None = None, | ||
| autofilter_range: str | None = None, |
There was a problem hiding this comment.
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.
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.
doc/source/whatsnew/v3.0.0.rstfile if fixing a bug or adding a new feature.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.