@@ -404,6 +404,10 @@ def read_excel(
404
404
405
405
class BaseExcelReader (metaclass = abc .ABCMeta ):
406
406
def __init__ (self , filepath_or_buffer , storage_options : StorageOptions = None ):
407
+ # First argument can also be bytes, so create a buffer
408
+ if isinstance (filepath_or_buffer , bytes ):
409
+ filepath_or_buffer = BytesIO (filepath_or_buffer )
410
+
407
411
self .handles = IOHandles (
408
412
handle = filepath_or_buffer , compression = {"method" : None }
409
413
)
@@ -422,8 +426,6 @@ def __init__(self, filepath_or_buffer, storage_options: StorageOptions = None):
422
426
except Exception :
423
427
self .close ()
424
428
raise
425
- elif isinstance (self .handles .handle , bytes ):
426
- self .book = self .load_workbook (BytesIO (self .handles .handle ))
427
429
else :
428
430
raise ValueError (
429
431
"Must explicitly set engine if not passing in buffer or path for io."
@@ -1111,7 +1113,7 @@ class ExcelFile:
1111
1113
1112
1114
Parameters
1113
1115
----------
1114
- path_or_buffer : str, path object (pathlib.Path or py._path.local.LocalPath),
1116
+ path_or_buffer : str, bytes, path object (pathlib.Path or py._path.local.LocalPath),
1115
1117
a file-like object, xlrd workbook or openpyxl workbook.
1116
1118
If a string or path object, expected to be a path to a
1117
1119
.xls, .xlsx, .xlsb, .xlsm, .odf, .ods, or .odt file.
@@ -1170,6 +1172,10 @@ def __init__(
1170
1172
if engine is not None and engine not in self ._engines :
1171
1173
raise ValueError (f"Unknown engine: { engine } " )
1172
1174
1175
+ # First argument can also be bytes, so create a buffer
1176
+ if isinstance (path_or_buffer , bytes ):
1177
+ path_or_buffer = BytesIO (path_or_buffer )
1178
+
1173
1179
# Could be a str, ExcelFile, Book, etc.
1174
1180
self .io = path_or_buffer
1175
1181
# Always a string
0 commit comments