From 0fff857d7f366dc4cdaaaa7f6bde7e936742dc48 Mon Sep 17 00:00:00 2001 From: alexeikhatin Date: Wed, 5 Aug 2020 15:54:26 +0300 Subject: [PATCH 1/2] DOC: add type BinaryIO to path param #35505 --- pandas/io/excel/_base.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index b1bbda4a4b7e0..7bb5a5004a16b 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -541,7 +541,7 @@ class ExcelWriter(metaclass=abc.ABCMeta): Parameters ---------- - path : str + path : str or BinaryIO Path to xls or xlsx or ods file. engine : str (optional) Engine to use for writing. If None, defaults to @@ -596,6 +596,21 @@ class ExcelWriter(metaclass=abc.ABCMeta): >>> with ExcelWriter('path_to_file.xlsx', mode='a') as writer: ... df.to_excel(writer, sheet_name='Sheet3') + + You can store Excel file in RAM: + + >>> import io + >>> buffer = io.BytesIO() + >>> with pd.ExcelWriter(buffer) as writer: + ... df.to_excel(writer) + + You can pack Excel file into zip archive: + + >>> import zipfile + >>> with zipfile.ZipFile('path_to_file.zip', 'w') as zf: + ... with zf.open('filename.xlsx', 'w') as buffer: + ... with pd.ExcelWriter(buffer) as writer: + ... df.to_excel(writer) """ # Defining an ExcelWriter implementation (see abstract methods for more...) From 722215d24d44b68218212928e0cec8a51e520a5b Mon Sep 17 00:00:00 2001 From: alexeikhatin Date: Mon, 24 Aug 2020 17:22:28 +0300 Subject: [PATCH 2/2] DOC: add type BinaryIO to path param #35505 --- pandas/io/excel/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 7bb5a5004a16b..e31acbbb1614a 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -541,7 +541,7 @@ class ExcelWriter(metaclass=abc.ABCMeta): Parameters ---------- - path : str or BinaryIO + path : str or typing.BinaryIO Path to xls or xlsx or ods file. engine : str (optional) Engine to use for writing. If None, defaults to