From 473ee14be57f000658e94dde082bda15f7a311f3 Mon Sep 17 00:00:00 2001 From: vinraspa <78381185+vinraspa@users.noreply.github.com> Date: Wed, 15 Sep 2021 18:26:09 +0200 Subject: [PATCH] Update xlsw.py added 'timedelta' support --- pyexcel_xls/xlsw.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyexcel_xls/xlsw.py b/pyexcel_xls/xlsw.py index e348b9a..c07a9b3 100644 --- a/pyexcel_xls/xlsw.py +++ b/pyexcel_xls/xlsw.py @@ -52,6 +52,14 @@ class XLSheetWriter(ISheetWriter): value = xlrd.xldate.xldate_from_datetime_tuple(tmp_array, 0) style = XFStyle() style.num_format_str = DEFAULT_DATETIME_FORMAT + elif isinstance(value, datetime.timedelta): + hours = value.days * 24 + value.seconds // 3600 + minutes = (value.seconds // 60) % 60 + seconds = value.seconds % 60 + tmp_array = [hours, minutes, seconds] + value = xlrd.xldate.xldate_from_time_tuple(tmp_array) + style = XFStyle() + style.num_format_str = DEFAULT_TIME_FORMAT elif isinstance(value, datetime.date): tmp_array = [value.year, value.month, value.day] value = xlrd.xldate.xldate_from_date_tuple(tmp_array, 0)