jazzband / tablib

Python Module for Tabular Datasets in XLS, CSV, JSON, YAML, &c.
https://tablib.readthedocs.io/
MIT License
4.58k stars 589 forks source link

Databook unable to load xls #522

Closed wanmi59 closed 11 months ago

wanmi59 commented 2 years ago

I'm trying to load an xls file however it fails with the following error

with open("xls_file", "rb") as fh: 
    imported_data = Databook().load(fh, "xls")
Traceback (most recent call last):
  File ".\test.py", line 5, in <module>
    imported_data = Databook().load(fh, "xls")
  File "lib\site-packages\tablib\core.py", line 872, in load
    fmt.import_book(self, stream, **kwargs)
  File "lib\site-packages\tablib\formats\_xls.py", line 103, in import_book
    xls_book = xlrd.open_workbook(file_contents=in_stream)
  File "lib\site-packages\xlrd\__init__.py", line 166, in open_workbook
    file_format = inspect_format(filename, file_contents)
  File "lib\site-packages\xlrd\__init__.py", line 57, in inspect_format
    peek = content[:PEEK_SIZE]
TypeError: '_io.BufferedReader' object is not subscriptable
harkabeeparolus commented 2 years ago

Databook is not supported for xls, only for xlsx.

You should probably avoid using xls files wherever possible, xlsx is the default Office format since 2007.

jpvanhal commented 11 months ago

Databook is not supported for xls, only for xlsx.

Could you please provide more context or clarify where you came across the information stating that databook is not supported for XLS? I noticed that in the documentation, there's an example of exporting a databook as XLS, and the XLSFormat class seems to implement both both export_book and import_book methods. Additionally, when checking the tests, XLS is not listed as an unsupported format for books. So the evidence suggests that Databook indeed supports XLS format.

harkabeeparolus commented 11 months ago

Databook is not supported for xls, only for xlsx.

So the evidence suggests that Databook indeed supports XLS format.

You are right! My bad. 😳

I do however stand by the other part of my statement, which is that XLS is old and creaky and should be avoided. 😊

claudep commented 11 months ago

…XLS is old and creaky and should be avoided.

Of course, however you don't always have the choice, typically when you are not the data producer.