-
-
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
Changes from 3 commits
90f75a5
6bc6952
d1b05e8
1365c21
f69c62f
ecfd509
5160d24
0ba5cad
d87e245
1f33aad
4f7085a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -532,6 +532,8 @@ class ExcelFormatter: | |||||
| Defaults to ``CSSToExcelConverter()``. | ||||||
| It should have signature css_declarations string -> excel style. | ||||||
| This is only called for body cells. | ||||||
| autofilter : bool, default False | ||||||
| If True, add automatic filters to all columns | ||||||
|
||||||
| If True, add automatic filters to all columns | |
| If True, add automatic filters to all columns. |
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.
Done!
WillAyd marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -350,3 +350,20 @@ def test_format_hierarchical_rows_periodindex(merge_cells): | |
| assert isinstance(cell.val, Timestamp), ( | ||
| "Period should be converted to Timestamp" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("engine", ["xlsxwriter", "openpyxl"]) | ||
| def test_autofilter(engine, tmp_excel): | ||
| # GH 61194 | ||
| df = DataFrame.from_dict([{"A": 1, "B": 2, "C": 3}, {"A": 4, "B": 5, "C": 6}]) | ||
|
|
||
| with ExcelWriter(tmp_excel, engine=engine) as writer: | ||
| df.to_excel(writer, autofilter=True, index=False) | ||
|
|
||
| openpyxl = pytest.importorskip("openpyxl") # test loading only with openpyxl | ||
| with contextlib.closing(openpyxl.load_workbook(tmp_excel)) as wb: | ||
| ws = wb.active | ||
|
|
||
| assert ws.auto_filter.ref is not None | ||
| print(ws.auto_filter.ref) | ||
|
||
| assert ws.auto_filter.ref == "A1:D3" | ||
Uh oh!
There was an error while loading. Please reload this page.