Skip to content

Commit 18d9eab

Browse files
author
Joeperdefloep
committed
BUG: excelwriter engine_kwargs fix
1 parent 3ce150d commit 18d9eab

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

pandas/io/excel/_base.py

+13
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,19 @@ class ExcelWriter(metaclass=abc.ABCMeta):
754754
>>> with ExcelWriter("path_to_file.xlsx", mode="a", engine="openpyxl") as writer:
755755
... df.to_excel(writer, sheet_name="Sheet3")
756756
757+
Here, the `if_sheet_exists` parameter can be set to replace a sheet if it
758+
already exists:
759+
760+
>>> with ExcelWriter("path_to_file.xlsx", mode="a", engine="openpyxl", if_sheet_exists="replace") as writer:
761+
... df.to_excel(writer, sheet_name="Sheet1")
762+
763+
You can specify arguments to the underlying engine. For example to not
764+
calculate the result of a formula:
765+
766+
>>> df = pd.DataFrame(["=1+1"])
767+
... with ExcelWriter("path_to_file.xlsx", engine_kwargs={"strings_to_formulas":False})
768+
... df.to_excel(writer)
769+
757770
You can store Excel file in RAM:
758771
759772
>>> import io

pandas/io/excel/_xlsxwriter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def __init__(
195195
engine_kwargs=engine_kwargs,
196196
)
197197

198-
self.book = Workbook(self.handles.handle, **engine_kwargs)
198+
self.book = Workbook(self.handles.handle, engine_kwargs)
199199

200200
def save(self):
201201
"""

pandas/tests/io/excel/test_xlsxwriter.py

+4
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ def test_write_append_mode_raises(ext):
6161
with tm.ensure_clean(ext) as f:
6262
with pytest.raises(ValueError, match=msg):
6363
ExcelWriter(f, engine="xlsxwriter", mode="a")
64+
65+
def test_engine_kwargs(ext):
66+
with tm.ensure_clean(ext) as f:
67+
ExcelWriter(f,engine="xlsxwriter",engine_kwargs={"strings_to_formulas":False})

0 commit comments

Comments
 (0)