Browse Source

autodetect boolean type

pull/284/head
Luc De Meyer 6 years ago
parent
commit
6b499c0a8f
  1. 10
      report_xlsx_helper/report/abstract_report_xlsx.py

10
report_xlsx_helper/report/abstract_report_xlsx.py

@ -502,12 +502,14 @@ class AbstractReportXlsx(ReportXlsx):
cell_type = cell_spec.get('type') cell_type = cell_spec.get('type')
cell_format = cell_spec.get('format') or default_format cell_format = cell_spec.get('format') or default_format
if not cell_type: if not cell_type:
if isinstance(cell_value, basestring):
# test bool first since isinstance(val, int) returns
# True when type(val) is bool
if isinstance(cell_value, bool):
cell_type = 'boolean'
elif isinstance(cell_value, basestring):
cell_type = 'string' cell_type = 'string'
elif isinstance(cell_value, (int, float)):
elif isinstance(cell_value, (int, long, float)):
cell_type = 'number' cell_type = 'number'
elif isinstance(cell_value, bool):
cell_type = 'boolean'
elif isinstance(cell_value, datetime): elif isinstance(cell_value, datetime):
cell_type = 'datetime' cell_type = 'datetime'
else: else:

Loading…
Cancel
Save