mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Fixes #462 - Update xlsx import to read cell values instead of cell formulas
Co-authored-by: Claude Paroz <claude@2xlibre.net>
This commit is contained in:
@@ -13,6 +13,10 @@
|
||||
- Fixed minimal openpyxl dependency version to 2.6.0 (#457).
|
||||
- Dates from xls files are now read as Python datetime objects (#373).
|
||||
|
||||
### Improvements
|
||||
|
||||
- When importing an xlsx file, Tablib will now read cell values instead of formulas (#462).
|
||||
|
||||
## 1.1.0 (2020-02-13)
|
||||
|
||||
### Deprecations
|
||||
|
||||
@@ -206,6 +206,15 @@ Import/export data in Excel 07+ Spreadsheet representation.
|
||||
This format is optional, install Tablib with ``pip install tablib[xlsx]`` to
|
||||
make the format available.
|
||||
|
||||
.. note::
|
||||
|
||||
When reading an ``xlsx`` file containing formulas in its cells, Tablib will
|
||||
read the cell values, not the cell formulas.
|
||||
|
||||
.. versionchanged:: 2.0.0
|
||||
|
||||
Reads cell values instead of formulas.
|
||||
|
||||
.. admonition:: Binary Warning
|
||||
|
||||
The ``xlsx`` file format is binary, so make sure to write in binary mode::
|
||||
|
||||
@@ -63,7 +63,7 @@ class XLSXFormat:
|
||||
|
||||
dset.wipe()
|
||||
|
||||
xls_book = load_workbook(in_stream, read_only=True)
|
||||
xls_book = load_workbook(in_stream, read_only=True, data_only=True)
|
||||
sheet = xls_book.active
|
||||
|
||||
dset.title = sheet.title
|
||||
@@ -81,7 +81,7 @@ class XLSXFormat:
|
||||
|
||||
dbook.wipe()
|
||||
|
||||
xls_book = load_workbook(in_stream, read_only=True)
|
||||
xls_book = load_workbook(in_stream, read_only=True, data_only=True)
|
||||
|
||||
for sheet in xls_book.worksheets:
|
||||
data = tablib.Dataset()
|
||||
|
||||
Binary file not shown.
@@ -1023,6 +1023,13 @@ class XLSXTests(BaseTestCase):
|
||||
data.append(('string', b'\x0cf'))
|
||||
data.xlsx
|
||||
|
||||
def test_xlsx_cell_values(self):
|
||||
"""Test cell values are read and not formulas"""
|
||||
xls_source = Path(__file__).parent / 'files' / 'xlsx_cell_values.xlsx'
|
||||
with xls_source.open('rb') as fh:
|
||||
data = tablib.Dataset().load(fh)
|
||||
self.assertEqual(data.headers[0], 'Hello World')
|
||||
|
||||
|
||||
class JSONTests(BaseTestCase):
|
||||
def test_json_format_detect(self):
|
||||
|
||||
Reference in New Issue
Block a user