When passed to .setValue it raises AttributeError: datetime object has no attribute getTypes.
Any datetime in a spreadsheet (Excel, Gnumeric, Calc, historic ones) is a floating point number counting days and fractions of days since day zero 1899-12-30 00:00:00
. Therefore, your Python program needs to calculate this difference between your wanted datetime and point zero on the time scale. Unlike Excel, Calc accepts negative day numbers until year 1. Spreadsheet functions (easterdate, weekday, month etc.) work reliably back until 1582-10-15 (start of Gregorian Calendar).
P.S. alternative method: oCell.setFormula(time.strftime('%Y-%m-%d %H:%M:%S')
which writes the ISO datetime string as a formula into the cell. Every cell has a formula string, regardless of content:
‘’ Empty string
‘123.987’
‘ABCDE’
‘=SUM(A1:B99)’
'‘12345’ numeric string with leading apostrophe.
Even further into the past, dates BCE are supported, like -0123-11-22
Note that year 0 does not exist, after -0001-12-31 follows 0001-01-01
The gotcha is use of Julian calendar for display of dates before 1582-10-15
, which is my pet bug tdf#144699
Thank you, it looks very good and seems to be the correct approach. I’ll definitely try it later when I have more time and either read all the code or not in a situation where running unverified code is not allowed.