-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
ENH: Add autofilter parameter to DataFrame.to_excel #62928
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
|
Hi @rhshadrach, I hope you’re doing well. |
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.
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=Trueandmerge_cells=False.
| autofilter: bool = False, | ||
| ) -> None: | ||
| """ | ||
| Write object to an Excel sheet. |
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 doc decorator on L2149
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.
Also - it looks like there was a merge issue here and code got duplicated below.
| # track bounds (1-based for openpyxl) | ||
| if min_r is None or abs_row < min_r: |
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.
Are we able to determine these by startrow / startcol along with the DataFrame shape?
Okay, Im working on them now |
2558c20 to
e4012f0
Compare
|
Hi @rhshadrach . |
…ge for xlsxwriter/openpyxl; keep engine_kwargs semantics intact
…ter and a user guide snippet
- 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
8e3abb2 to
44010db
Compare
@rhshadrach
Adds an
autofilterparameter toDataFrame.to_excel()to enable Excel autofilterover the header row and data range when writing files.
Usage:
Supports
xlsxwriterandopenpyxlengines. Whenautofilter=True, applies anautofilter over the written data range (header row through last data row).
Closes #62651