File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 11import abc
22import datetime
3- from io import BytesIO
3+ from io import BytesIO , IOBase
44import os
55from textwrap import fill
66
@@ -778,6 +778,17 @@ def close(self):
778778 return self .save ()
779779
780780
781+ def _is_ods_stream (stream ):
782+ stream .seek (0 )
783+ is_ods = False
784+ if stream .read (4 ) == b"PK\003 \004 " :
785+ stream .seek (30 )
786+ is_ods = stream .read (54 ) == b"mimetype" \
787+ b"application/vnd.oasis.opendocument.spreadsheet"
788+ stream .seek (0 )
789+ return is_ods
790+
791+
781792class ExcelFile :
782793 """
783794 Class for parsing tabular excel sheets into DataFrame objects.
@@ -809,9 +820,12 @@ class ExcelFile:
809820 def __init__ (self , path_or_io , engine = None ):
810821 if engine is None :
811822 engine = "xlrd"
812- if isinstance (path_or_io , str ):
813- ext = os .path .splitext (path_or_io )[- 1 ][1 :]
814- if ext == "ods" :
823+ if isinstance (path_or_io , IOBase ):
824+ if _is_ods_stream (path_or_io ):
825+ engine = "odf"
826+ else :
827+ ext = os .path .splitext (str (path_or_io ))[- 1 ]
828+ if ext == ".ods" :
815829 engine = "odf"
816830 if engine not in self ._engines :
817831 raise ValueError (f"Unknown engine: { engine } " )
You can’t perform that action at this time.
0 commit comments