From 205403d377d4b6cb7f2b0fb48044442069269992 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Tue, 22 Oct 2019 20:45:21 +0200 Subject: [PATCH] Fixes #202 - Keep error content when importing xls files --- HISTORY.md | 1 + src/tablib/formats/_xls.py | 5 ++++- tests/files/errors.xls | Bin 0 -> 5632 bytes tests/test_tablib.py | 29 ++++++++++++++++++++++++----- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 tests/files/errors.xls diff --git a/HISTORY.md b/HISTORY.md index aaccbb0..58de623 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,7 @@ ### Bugfixes - Fixed a crash when exporting an empty string with the ReST format (#368) +- Error cells from imported .xls files contain now the error string (#202) ## 0.14.0 (2019-10-19) diff --git a/src/tablib/formats/_xls.py b/src/tablib/formats/_xls.py index 3fc94af..0533476 100644 --- a/src/tablib/formats/_xls.py +++ b/src/tablib/formats/_xls.py @@ -76,7 +76,10 @@ def import_set(dset, in_stream, headers=True): if (i == 0) and (headers): dset.headers = sheet.row_values(0) else: - dset.append(sheet.row_values(i)) + dset.append([ + val if typ != xlrd.XL_CELL_ERROR else xlrd.error_text_from_code[val] + for val, typ in zip(sheet.row_values(i), sheet.row_types(i)) + ]) def import_book(dbook, in_stream, headers=True): diff --git a/tests/files/errors.xls b/tests/files/errors.xls new file mode 100644 index 0000000000000000000000000000000000000000..08693375ea12888993c6f70b8c7597d8e8d15794 GIT binary patch literal 5632 zcmeHLU1(fI6h8OvPjAwnY|^A^f8sT@o6VoJ2DBn=H~rIsZ9}XmrJ#2=H*xL$lyuWt zP`XX+L&1X52VV+O2#8etLDUBY(+9x^MJWVYK}h>n^kFMiDYRX`Z|=Rx?V3$DT9ry> zIWuR@oHJ+U%$YOi?)Tr-Pn`Z}=|w3kk4r#qmTDyIqietouOAW7fs=N#R4RF7pmXIe zvcL^@tvtgZ4lxAana=}|R^zsJ(U#_xItvT*Ne;ifn6gE(XoutwPQ3cE1Rmp8SB<1U zUR1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