Skip to content

Commit

Permalink
fix(ods): None values are not displayed as string
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine committed Nov 8, 2023
1 parent 9ef5584 commit aec46cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/tablib/formats/_ods.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ def dset_sheet(cls, dataset, ws):
cell = table.TableCell(valuetype="date", datevalue=col.strftime('%Y-%m-%d'))
elif isinstance(col, dt.time):
cell = table.TableCell(valuetype="time", timevalue=col.strftime('%H:%M:%S'))
elif col is None:
cell = table.TableCell(valuetype="void")
else:
cell = table.TableCell(valuetype="string")
cell.addElement(text.P(text=str(col), stylename=style))
Expand Down
5 changes: 3 additions & 2 deletions tests/test_tablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,9 +1111,9 @@ def test_ods_export_import_set(self):
date = dt.date(2019, 10, 4)
date_time = dt.datetime(2019, 10, 4, 12, 30, 8)
time = dt.time(14, 30)
data.append(('string', '004', 42, 21.55, Decimal('34.5'), date, time, date_time))
data.append(('string', '004', 42, 21.55, Decimal('34.5'), date, time, date_time, None))
data.headers = (
'string', 'start0', 'integer', 'float', 'decimal', 'date', 'time', 'date/time'
'string', 'start0', 'integer', 'float', 'decimal', 'date', 'time', 'date/time', 'None'
)
_ods = data.ods
data.ods = _ods
Expand All @@ -1125,6 +1125,7 @@ def test_ods_export_import_set(self):
self.assertEqual(data.dict[0]['date'], date)
self.assertEqual(data.dict[0]['time'], time)
self.assertEqual(data.dict[0]['date/time'], date_time)
self.assertEqual(data.dict[0]['None'], '')

def test_ods_import_book(self):
ods_source = Path(__file__).parent / 'files' / 'book.ods'
Expand Down

0 comments on commit aec46cb

Please sign in to comment.