File tree 1 file changed +18
-4
lines changed
1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 1
1
import abc
2
2
import datetime
3
- from io import BytesIO
3
+ from io import BytesIO , IOBase
4
4
import os
5
5
from textwrap import fill
6
6
@@ -778,6 +778,17 @@ def close(self):
778
778
return self .save ()
779
779
780
780
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
+
781
792
class ExcelFile :
782
793
"""
783
794
Class for parsing tabular excel sheets into DataFrame objects.
@@ -816,9 +827,12 @@ class ExcelFile:
816
827
def __init__ (self , path_or_io , engine = None ):
817
828
if engine is None :
818
829
engine = "xlrd"
819
- if isinstance (path_or_io , str ):
820
- ext = os .path .splitext (path_or_io )[- 1 ][1 :]
821
- if ext == "ods" :
830
+ if isinstance (path_or_io , IOBase ):
831
+ if _is_ods_stream (path_or_io ):
832
+ engine = "odf"
833
+ else :
834
+ ext = os .path .splitext (str (path_or_io ))[- 1 ]
835
+ if ext == ".ods" :
822
836
engine = "odf"
823
837
if engine not in self ._engines :
824
838
raise ValueError (f"Unknown engine: { engine } " )
You can’t perform that action at this time.
0 commit comments