mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Fixes #314 - Delegate type coercion to openpyxl
Thanks Cristiano Lopes for the initial patch.
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
- The project is now maintained by the Jazzband team, https://jazzband.co
|
||||
- Fixed `DataBook().load` parameter ordering (first stream, then format).
|
||||
- Fixed a regression for xlsx exports where non-string values were forced to
|
||||
strings (#314).
|
||||
- Added search to all documentation pages
|
||||
- Open xlsx workbooks in read-only mode (#316)
|
||||
- Unpin requirements
|
||||
|
||||
@@ -117,8 +117,6 @@ def dset_sheet(dataset, ws, freeze_panes=True):
|
||||
|
||||
# bold headers
|
||||
if (row_number == 1) and dataset.headers:
|
||||
# cell.value = unicode('%s' % col, errors='ignore')
|
||||
cell.value = unicode(col)
|
||||
cell.font = bold
|
||||
if freeze_panes:
|
||||
# Export Freeze only after first Line
|
||||
@@ -126,16 +124,18 @@ def dset_sheet(dataset, ws, freeze_panes=True):
|
||||
|
||||
# bold separators
|
||||
elif len(row) < dataset.width:
|
||||
cell.value = unicode('%s' % col, errors='ignore')
|
||||
cell.font = bold
|
||||
|
||||
# wrap the rest
|
||||
else:
|
||||
try:
|
||||
if '\n' in col:
|
||||
cell.value = unicode('%s' % col, errors='ignore')
|
||||
cell.alignment = wrap_text
|
||||
else:
|
||||
cell.value = unicode('%s' % col, errors='ignore')
|
||||
str_col_value = unicode(col)
|
||||
except TypeError:
|
||||
cell.value = unicode(col)
|
||||
str_col_value = ''
|
||||
if '\n' in str_col_value:
|
||||
cell.alignment = wrap_text
|
||||
|
||||
try:
|
||||
cell.value = col
|
||||
except (ValueError, TypeError):
|
||||
cell.value = unicode(col)
|
||||
|
||||
@@ -782,6 +782,25 @@ class TSVTests(BaseTestCase):
|
||||
self.assertEqual(tsv, self.founders.tsv)
|
||||
|
||||
|
||||
class XLSXTests(BaseTestCase):
|
||||
def test_xlsx_import_set(self):
|
||||
data.append(('string', 42, 21.55))
|
||||
data.headers = ('string', 'integer', 'float')
|
||||
_xlsx = data.xlsx
|
||||
data.xlsx = _xlsx
|
||||
self.assertEqual(data.dict[0]['string'], 'string')
|
||||
self.assertEqual(data.dict[0]['integer'], 42)
|
||||
self.assertEqual(data.dict[0]['float'], 21.55)
|
||||
|
||||
def test_xlsx_wrong_char(self):
|
||||
"""Bad characters are not silently ignored. We let the exception bubble up."""
|
||||
from openpyxl.utils.exceptions import IllegalCharacterError
|
||||
|
||||
with self.assertRaises(IllegalCharacterError):
|
||||
data.append(('string', b'\x0cf'))
|
||||
data.xlsx
|
||||
|
||||
|
||||
class JSONTests(BaseTestCase):
|
||||
def test_json_format_detect(self):
|
||||
"""Test JSON format detection."""
|
||||
|
||||
Reference in New Issue
Block a user