How to export to excel datetime in Django 1.7

Iam using Django 1.7, Python 3.4, and PostgreSQL 9.1. I need to export some set of queries to Excel. I use this tutorial as a starting point: outputting-excel-with-django

In my model I have a field as Datetime , and in utils.py I have already added the style:(datetime.datetime, xlwt.easyxf(num_format_str='DD/MM/YYYY HH:MM:SS')),

But when I try to export my data, I get a Type Error: can't subtract offset-naive and offset-aware datetimes

Can anyone help me? Thanks to

+3


source to share


2 answers


Your problem appears to be related to knowledgeable and naive datetimes .

You should be giving you datetime objects. You can install pytz for this:

pip install pytz

      



And then find out about your datetime objects:

import pytz

(pytz.utc.localize(datetime.datetime), xlwt.easyxf(num_format_str='DD/MM/YYYY HH:MM:SS')),

      

Hope it helps.

+2


source


You can use xlsxwriter for this
https://pypi.python.org/pypi/XlsxWriter



+1


source







All Articles