From 41de75933260ded895586b30d8e0312967d91c8f Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Fri, 10 Aug 2018 12:22:33 +0200 Subject: [PATCH] autodetect boolean type --- report_xlsx_helper/report/abstract_report_xlsx.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/report_xlsx_helper/report/abstract_report_xlsx.py b/report_xlsx_helper/report/abstract_report_xlsx.py index a3731ea54..37fd8ed72 100644 --- a/report_xlsx_helper/report/abstract_report_xlsx.py +++ b/report_xlsx_helper/report/abstract_report_xlsx.py @@ -502,12 +502,14 @@ class AbstractReportXlsx(ReportXlsx): cell_type = cell_spec.get('type') cell_format = cell_spec.get('format') or default_format if not cell_type: - if isinstance(cell_value, basestring): - cell_type = 'string' - elif isinstance(cell_value, (int, float)): - cell_type = 'number' - elif isinstance(cell_value, bool): + # 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' + elif isinstance(cell_value, (int, long, float)): + cell_type = 'number' elif isinstance(cell_value, datetime): cell_type = 'datetime' else: