34
34
"""
35
35
Read an Excel file into a pandas DataFrame.
36
36
37
- Supports `xls`, `xlsx`, `xlsm`, `xlsb`, and `odf ` file extensions
37
+ Supports `xls`, `xlsx`, `xlsm`, `xlsb`, `odf`, `ods` and `odt ` file extensions
38
38
read from a local filesystem or URL. Supports an option to read
39
39
a single sheet or a list of sheets.
40
40
105
105
If io is not a buffer or path, this must be set to identify io.
106
106
Acceptable values are None, "auto", "xlrd", "openpyxl", "odf", or "pyxlsb".
107
107
File compatibility:
108
- "xlrd" engine supports .xls, and .xlsx files.
109
- "openpyxl" engine supports .xlsx, .xlsm, .xltx, and .xltm files.
110
- "odf" engine supports .odf files.
108
+ "xlrd" engine supports .xls, .xlsx, and .xlsm files.
109
+ "openpyxl" engine supports .xlsx, and .xlsm files.
110
+ "odf" engine supports .odf, .ods, and .odt files.
111
111
"pyxlsb" engine supports .xlsb files.
112
112
converters : dict, default None
113
113
Dict of functions for converting values in certain columns. Keys can
@@ -802,9 +802,9 @@ class ExcelFile:
802
802
Acceptable values are None, ``auto``, ``xlrd``, ``openpyxl``,
803
803
``odf``, or ``pyxlsb``.
804
804
File compatibility:
805
- ``xlrd`` engine supports .xls, and .xlsx files.
806
- ``openpyxl`` engine supports .xlsx, .xlsm, .xltx, and .xltm files.
807
- ``odf`` engine supports .odf files.
805
+ ``xlrd`` engine supports .xls, .xlsx, and .xlsm files.
806
+ ``openpyxl`` engine supports .xlsx, and .xlsm files.
807
+ ``odf`` engine supports .odf, .ods, and .odt files.
808
808
``pyxlsb`` engine supports .xlsb files.
809
809
"""
810
810
@@ -820,10 +820,12 @@ class ExcelFile:
820
820
"pyxlsb" : _PyxlsbReader ,
821
821
}
822
822
823
+ # Excel templates are not supported by read_excel according to the
824
+ # documentation, but openpyxl specifies them as supported.
823
825
_supported_engine_filetypes = {
824
- "xlrd" : ["xls" , "xlsx" ],
826
+ "xlrd" : ["xls" , "xlsx" , "xlsm" ],
825
827
"openpyxl" : ["xlsx" , "xlsm" , "xltx" , "xltm" ],
826
- "odf" : ["odf" ],
828
+ "odf" : ["odf" , "ods" , "odt" ],
827
829
"pyxlsb" : ["xlsb" ],
828
830
}
829
831
@@ -834,13 +836,15 @@ def __init__(self, io, engine=None):
834
836
raise ValueError (f"Unknown engine: { engine } " )
835
837
836
838
self .engine = engine
837
- # could be a str, ExcelFile, Book, etc.
839
+
840
+ # 'io' could be a str, ExcelFile, Book, etc.
841
+ if isinstance (io , str ):
842
+ # Check engine-extension compatibility
843
+ ext = os .path .splitext (io )[- 1 ][1 :]
844
+ self .check_extension (engine , ext )
838
845
self .io = io
839
846
# Always a string
840
847
self ._io = stringify_path (io )
841
- # Check engine-extension compatibility
842
- ext = os .path .splitext (io )[- 1 ][1 :]
843
- self .check_extension (engine , ext )
844
848
845
849
self ._reader = self ._engines [engine ](self ._io )
846
850
0 commit comments