Today I tried to save a worksheet with the date 01/01/0001, represented by the object
datetime.datetime(1, 1, 1), and openpyxl raised the following error:
from openpyxl import Workbook import datetime wb = Workbook() wb.active['A1'] = datetime.datetime(1,1,1) wb.save('test.xlsx') >>> ValueError: year is out of range
This error is raised inside the
from_excel function at
openpyxl.utils.datetime, by the
It seems that this constructor uses a slice of the
parts variable, representing the year, month and date of a given value.
The problem is (or at least I think it is) that when processing the date 01/01/0001, that triplet has the values
[0, 12, 31], thus, raising the error for a year out of range.