Skip to content

Commit

Permalink
Fix crash when loading databook from XLS
Browse files Browse the repository at this point in the history
`xlrd.open_workbook()` function expects the `file_contents` argument to
be a string.

Fixes #522
  • Loading branch information
jpvanhal authored and claudep committed Sep 23, 2023
1 parent 5431834 commit 95efc7b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tablib/formats/_xls.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def import_book(cls, dbook, in_stream, headers=True):

dbook.wipe()

xls_book = xlrd.open_workbook(file_contents=in_stream)
xls_book = xlrd.open_workbook(file_contents=in_stream.read())

for sheet in xls_book.sheets():
data = tablib.Dataset()
Expand Down
5 changes: 5 additions & 0 deletions tests/test_tablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,11 @@ def test_xls_import_with_errors(self):
])
)

def test_book_import_from_stream(self):
in_stream = self.founders.xls
book = tablib.Databook().load(in_stream, 'xls')
self.assertEqual(book.sheets()[0].title, 'Founders')


class XLSXTests(BaseTestCase):
def test_xlsx_format_detect(self):
Expand Down

0 comments on commit 95efc7b

Please sign in to comment.