Skip to content

Commit 7fc11b7

Browse files
authored
Update excel.py
1 parent 9c0cc9c commit 7fc11b7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pandas/io/formats/excel.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,10 @@
5353
if TYPE_CHECKING:
5454
from pandas._typing import (
5555
ExcelWriterMergeCells,
56-
FilePath,
5756
IndexLabel,
5857
StorageOptions,
59-
WriteExcelBuffer,
6058
)
6159

62-
from pandas import ExcelWriter
63-
6460

6561
class ExcelCell:
6662
__fields__ = ("row", "col", "val", "style", "mergestart", "mergeend")
@@ -874,16 +870,17 @@ def get_formatted_cells(self) -> Iterable[ExcelCell]:
874870
yield cell
875871

876872
@doc(storage_options=_shared_docs["storage_options"])
877-
def write(
873+
def to_excel(
878874
self,
879-
writer: FilePath | WriteExcelBuffer | ExcelWriter,
875+
writer,
880876
sheet_name: str = "Sheet1",
881877
startrow: int = 0,
882878
startcol: int = 0,
883879
freeze_panes: tuple[int, int] | None = None,
884880
engine: str | None = None,
885881
storage_options: StorageOptions | None = None,
886882
engine_kwargs: dict | None = None,
883+
autofilter: bool = False,
887884
) -> None:
888885
"""
889886
writer : path-like, file-like, or ExcelWriter object
@@ -931,12 +928,16 @@ def write(
931928
except Exception:
932929
# Best-effort propagation; ignore if engine does not support it
933930
pass
931+
# Set autofilter on existing writer
932+
if hasattr(writer, "autofilter"):
933+
writer.autofilter = autofilter
934934
else:
935935
writer = ExcelWriter(
936936
writer,
937937
engine=engine,
938938
storage_options=storage_options,
939939
engine_kwargs=engine_kwargs,
940+
autofilter=autofilter,
940941
)
941942
need_save = True
942943

0 commit comments

Comments
 (0)