jazzband / tablib

Python Module for Tabular Datasets in XLS, CSV, JSON, YAML, &c.
https://tablib.readthedocs.io/
MIT License
4.59k stars 590 forks source link

Alternative to xlwt. #476

Closed alexsilva closed 3 years ago

alexsilva commented 3 years ago

Python 3 Django 2 django-import-export

# Error: can't subtract offset-naive and offset-aware datetimes

Python3\lib\site-packages\xlwt\Row.py in __excel_date_dt
            if isinstance(date, dt.datetime):
                epoch = dt.datetime(*epoch_tuple)
            else:
                epoch = dt.date(*epoch_tuple)
        else: # it's a datetime.time instance
            date = dt.datetime.combine(dt.datetime(1900, 1, 1), date)
            epoch = dt.datetime(1900, 1, 1)
        delta = date - epoch
        xldate = delta.days + delta.seconds / 86400.0                      
        # Add a day for Excel's missing leap day in 1900
        if adj and xldate > 59:
            xldate += 1
        return xldate    

Context

Variable | Value
adj | True
date | datetime.datetime(2020, 10, 16, 16, 33, 41, tzinfo=<UTC>)
epoch | datetime.datetime(1899, 12, 31, 0, 0)
epoch_tuple | (1899, 12, 31)
self | <xlwt.Row.Row object at 0x10C2EF30>

This repository has been archived by the owner. It is now read-only.

https://github.com/python-excel/xlwt

claudep commented 3 years ago

Please could you be a little more explicit about the subject of you report?

Also note that xlrd/xlwt are only needed to open/write legacy xls files. You should prefer OpenXML .xlsx nowadays (for which tablib is using the well-maintained openpyxl).