DateTime issues in django xlsxwriter

前端 未结 1 1424
盖世英雄少女心
盖世英雄少女心 2021-01-14 06:11

I am trying to create an export to excel functionality in my django view as follows:

def export_myreport(request, sd, ed):
    from xlsxwriter.workbook impor         


        
相关标签:
1条回答
  • 2021-01-14 07:03

    Excel, and thus XlsxWriter, doesn't support timezones in dates/times.

    So you will need to remove or adjust the timezone from the datetime before passing it to XlsxWriter.

    Something like this from the pytz docs:

    dt = datetime(2005, 3, 1, 14, 13, 21, tzinfo=utc)
    naive = dt.replace(tzinfo=None)
    

    Probably this would be better handled in Django though rather than adjusting all datetime data prior to passing it to XlsxWriter. Maybe someone else can add a suggestion on that.

    0 讨论(0)
提交回复
热议问题