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.
@@ -809,9 +820,12 @@ class ExcelFile:
809
820
def __init__ (self , path_or_io , engine = None ):
810
821
if engine is None :
811
822
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" :
815
829
engine = "odf"
816
830
if engine not in self ._engines :
817
831
raise ValueError (f"Unknown engine: { engine } " )
You can’t perform that action at this time.
0 commit comments