|
53 | 53 | if TYPE_CHECKING: |
54 | 54 | from pandas._typing import ( |
55 | 55 | ExcelWriterMergeCells, |
56 | | - FilePath, |
57 | 56 | IndexLabel, |
58 | 57 | StorageOptions, |
59 | | - WriteExcelBuffer, |
60 | 58 | ) |
61 | 59 |
|
62 | | - from pandas import ExcelWriter |
63 | | - |
64 | 60 |
|
65 | 61 | class ExcelCell: |
66 | 62 | __fields__ = ("row", "col", "val", "style", "mergestart", "mergeend") |
@@ -874,16 +870,17 @@ def get_formatted_cells(self) -> Iterable[ExcelCell]: |
874 | 870 | yield cell |
875 | 871 |
|
876 | 872 | @doc(storage_options=_shared_docs["storage_options"]) |
877 | | - def write( |
| 873 | + def to_excel( |
878 | 874 | self, |
879 | | - writer: FilePath | WriteExcelBuffer | ExcelWriter, |
| 875 | + writer, |
880 | 876 | sheet_name: str = "Sheet1", |
881 | 877 | startrow: int = 0, |
882 | 878 | startcol: int = 0, |
883 | 879 | freeze_panes: tuple[int, int] | None = None, |
884 | 880 | engine: str | None = None, |
885 | 881 | storage_options: StorageOptions | None = None, |
886 | 882 | engine_kwargs: dict | None = None, |
| 883 | + autofilter: bool = False, |
887 | 884 | ) -> None: |
888 | 885 | """ |
889 | 886 | writer : path-like, file-like, or ExcelWriter object |
@@ -931,12 +928,16 @@ def write( |
931 | 928 | except Exception: |
932 | 929 | # Best-effort propagation; ignore if engine does not support it |
933 | 930 | pass |
| 931 | + # Set autofilter on existing writer |
| 932 | + if hasattr(writer, "autofilter"): |
| 933 | + writer.autofilter = autofilter |
934 | 934 | else: |
935 | 935 | writer = ExcelWriter( |
936 | 936 | writer, |
937 | 937 | engine=engine, |
938 | 938 | storage_options=storage_options, |
939 | 939 | engine_kwargs=engine_kwargs, |
| 940 | + autofilter=autofilter, |
940 | 941 | ) |
941 | 942 | need_save = True |
942 | 943 |
|
|
0 commit comments