MCPcopy
hub / github.com/pandas-dev/pandas / __init__

Method __init__

pandas/io/excel/_openpyxl.py:45–90  ·  view source on GitHub ↗
(  # pyright: ignore[reportInconsistentConstructor]
        self,
        path: FilePath | WriteExcelBuffer | ExcelWriter,
        engine: str | None = None,
        date_format: str | None = None,
        datetime_format: str | None = None,
        mode: str = "w",
        storage_options: StorageOptions | None = None,
        if_sheet_exists: ExcelWriterIfSheetExists | None = None,
        engine_kwargs: dict[str, Any] | None = None,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

43 _supported_extensions = (".xlsx", ".xlsm")
44
45 def __init__( # pyright: ignore[reportInconsistentConstructor]
46 self,
47 path: FilePath | WriteExcelBuffer | ExcelWriter,
48 engine: str | None = None,
49 date_format: str | None = None,
50 datetime_format: str | None = None,
51 mode: str = "w",
52 storage_options: StorageOptions | None = None,
53 if_sheet_exists: ExcelWriterIfSheetExists | None = None,
54 engine_kwargs: dict[str, Any] | None = None,
55 **kwargs,
56 ) -> None:
57 # Use the openpyxl module as the Excel writer.
58 from openpyxl.workbook import Workbook
59
60 engine_kwargs = combine_kwargs(engine_kwargs, kwargs)
61
62 super().__init__(
63 path,
64 mode=mode,
65 storage_options=storage_options,
66 if_sheet_exists=if_sheet_exists,
67 engine_kwargs=engine_kwargs,
68 )
69
70 # ExcelWriter replaced "a" by "r+" to allow us to first read the excel file from
71 # the file and later write to it
72 if "r+" in self._mode: # Load from existing workbook
73 from openpyxl import load_workbook
74
75 try:
76 self._book = load_workbook(self._handles.handle, **engine_kwargs)
77 except TypeError:
78 self._handles.handle.close()
79 raise
80 self._handles.handle.seek(0)
81 else:
82 # Create workbook object with default optimized_write=True.
83 try:
84 self._book = Workbook(**engine_kwargs)
85 except TypeError:
86 self._handles.handle.close()
87 raise
88
89 if self.book.worksheets:
90 self.book.remove(self.book.worksheets[0])
91
92 @property
93 def book(self) -> Workbook:

Callers 1

__init__Method · 0.45

Calls 4

combine_kwargsFunction · 0.90
closeMethod · 0.45
seekMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected