question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DateField cannot be imported from Excel sheet containing dates

See original GitHub issue

Excel stores dates and times internally as floating point numbers where the integer part is the number of days since 31st December 1899 and the fractional part is the time of day. When loaded into a tablib Dataset these values remain as floating point.

Unfortunately the import_export DateWidget assumes that dates will be represented externally as strings and attempts to processing the floating point values using strptime leading to import errors such as shown below:

Line number: 1 - Column 'manufactured': Enter a valid date.

Traceback (most recent call last):
File ".../lib/python3.4/site-packages/import_export/fields.py", line 57, in clean
value = self.widget.clean(value)
File ".../lib/python3.4/site-packages/import_export/widgets.py", line 113, in clean
raise ValueError("Enter a valid date.")
ValueError: Enter a valid date.
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File ".../lib/python3.4/site-packages/import_export/resources.py", line 337, in import_data
self.import_obj(instance, row, real_dry_run)
File ".../lib/python3.4/site-packages/import_export/resources.py", line 203, in import_obj
self.import_field(field, obj, data)
ValueError: Column 'manufactured': Enter a valid date.

A simple fix for importing would be to change clean to accept float values in addition to parsing strings.

I believe a similar issue exists when exporting dates to Excel: they are currently output as strings which means any attempt to manipulate them as dates within Excel will fail. Simply converting to a float value on output would not be sufficient either as the cell would also need to be formatted as a date or time within Excel to display correctly.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
dwasylcommented, Mar 14, 2019

Having just run into this issue today, it would still be very good to get the code included in import-export @bmihelac

1reaction
manelcloscommented, Nov 13, 2018

@rhunwicks I’ve put the code in a gist, with updated clean() and render() signatures to work with latest django-import-export, here: https://gist.github.com/manelclos/5c37646120ec0520a9965df32cc6208a

@bmihelac It would be nice to have this in some compat.py file so people are able to use it directly from import-export without much hassle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lists: How do you import dates from Excel spreadsheet into
Firstly create a Date column in the list, then use Flow to import the Excel file to list, it will automatically import the...
Read more >
Problem in Date Field importing from Excel - in SSIS Package
I have a date column in which not all the rows are filled up with dates. In this column, in some of the...
Read more >
Importing dates from Excel into Sharepoint list
I have an extensive spreadsheet that I want to import a Sharepoint list. The issue is the date column. irrespective of how I...
Read more >
Solved: RE: Date Format issue - Import excel to SharePoint...
I have one date field in the excel template where the column ... I am importing an excel sheet into the SharePoint list...
Read more >
Maddening Problem Importing Dates From Excel
For a week, I've been trying to get SSIS to import dates from an Excel ... Excel sheet to strings using TEXT() with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found