Overflow error while converting a cell to date type

Issue #142 resolved
Ranjith Ramachandra
created an issue

I have noticed the library throws an overflow exception while trying to convert a cell which is a currency type to a date type.

I have temporarily solved the issue by catching the exception. I will fork send pull request though I am not sure if this is a real issue or a problem with data itself. I have attached the file

The sheet: "one sheet" has a column called Total amt in which many cells are some how determined as date types.

A typical log looks like:

Traceback (most recent call last):
  File "/home/ranjith/VENV/local/lib/python2.7/site-packages/openpyxl-1.5.8-py2.7.egg/openpyxl/reader/iter_worksheet.py", line 243, in get_squared_range
    cell = cell._replace(internal_value=shared_date.from_julian(float(cell.internal_value)))
  File "/home/ranjith/VENV/local/lib/python2.7/site-packages/openpyxl-1.5.8-py2.7.egg/openpyxl/shared/date_time.py", line 162, in from_julian
    return EPOCH + datetime.timedelta(days=utc_days)
OverflowError: date value out of range

Comments (9)

  1. Ed Staub

    I ran into this using openpyxl via pandas ExcelFile. The spreadsheet has a column titled "Page/Line/Column" with values like "1/11/1" and "1/35/3", a few of which weren't single-quoted to keep them from being interpreted as dates. I was trying to import the file to scrub it. Should l go back to xlrd?

  2. Ranjith Ramachandra reporter

    I do understand the issue now. But I will have to continue maintaining a local version of the library because I do expect to get data that has errors like that and not doing type guessing would be a bad idea for me. Anyhow, thanks for the library :)

  3. CharlieC

    Could you supply an example of a value that is causing the error? We probably have to improve the detection of date values.

    Apart from that I think we might need to review using type inference at all when reading existing Excel files. If we keep it around then we might at least allow it to be extended for handling custom values.

  4. Log in to comment