pyexcel-xls icon indicating copy to clipboard operation
pyexcel-xls copied to clipboard

Can't open xlsm files. Interfering with pyexcel-xlsx

Open zazuum opened this issue 2 years ago • 1 comments

Pyexcel throws an error when opening .xlsm files when both libraries are installed side by side (pyexcel-xls and pyexcel-xlsx). This is due to xlrd dropped support for anything other than reading .xls files since version 2.0.0. However pyexcel-xlsx handles .xlsm files without issues via openpyxl when pyexcel-xls is removed with (pip uninstall pyexcel-xls).

To reproduce the bug:

import pyexcel as p
p.get_book(file_name="Book.xlsm")

Result:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel/core.py", line 47, in get_book
    book_stream = sources.get_book_stream(**keywords)
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel/internal/core.py", line 38, in get_book_stream
    sheets = a_source.get_data()
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel/plugins/sources/file_input.py", line 38, in get_data
    sheets = self.__parser.parse_file(self.__file_name, **self._keywords)
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel/plugins/parsers/excel.py", line 19, in parse_file
    return self._parse_any(file_name, **keywords)
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel/plugins/parsers/excel.py", line 40, in _parse_any
    sheets = get_data(anything, file_type=file_type, **keywords)
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel_io/io.py", line 86, in get_data
    data, _ = _get_data(
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel_io/io.py", line 105, in _get_data
    return load_data(**keywords)
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel_io/io.py", line 191, in load_data
    reader.open(file_name, **keywords)
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel_io/reader.py", line 47, in open
    self.reader = self.reader_class(
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel_xls/xlsr.py", line 179, in __init__
    super().__init__(file_type, filename=file_name, **keywords)
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel_xls/xlsr.py", line 146, in __init__
    self.xls_book = self.get_xls_book(**xlrd_params)
  File "/home/ivan/.local/lib/python3.8/site-packages/pyexcel_xls/xlsr.py", line 165, in get_xls_book
    xls_book = xlrd.open_workbook(**xlrd_params)
  File "/home/ivan/.local/lib/python3.8/site-packages/xlrd/__init__.py", line 170, in open_workbook
    raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
xlrd.biffh.XLRDError: Excel xlsx file; not supported

For solution I created pull request that resolve the issue with reading .xlsm files and makes both libraries work side by side.

zazuum avatar Aug 12 '22 14:08 zazuum

i see.

chfw avatar Sep 16 '22 16:09 chfw