jazzband / tablib

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

How to preserve date format when export dataset to Excel file #498

Closed oussama-he closed 2 years ago

oussama-he commented 2 years ago

I've written a python script that creates a new Excel file from an existing one by copying some columns only. For this, I've used tablib library, but I'm facing an error with columns that have dates as values.

In the original file the format is like this 11/23/2007, but in the output file is like this 39409.

I'm saving the excel file like this:

with open('output-2.xls', 'wb') as f:
    new_dataset.headers = headers
    f.write(new_dataset.export('xls'))

When I print the new_dataset the column has datetime.datetime(11, 23, 2007, 0, 0) object as values

So, how can I preserve the dates format in the output file?

claudep commented 2 years ago

Are you really working with xls, not xlsx? I guess that you'd have more chances of a correct output with the xlsx format.

claudep commented 2 years ago

Closing for non-activity.