If I store a
datetime.date object in a worksheet cell and then immediately retrieve it, I get back the same
datetime.date object. If instead I store the
date object in a cell, write the workbook to disk, and then reload, when I retrieve the cell contents I get a
datetime.datetime object (with zero time part).
Either of these behaviours seems reasonable to me, but I'd expect to get the same type of object back regardless of whether I've saved the workbook out to disk or not.
This appears to be a regression from openpyxl 2.4, where a
date object stored in a cell is immediately converted to
(Versions: Python 3.7.2, macOS 10.14.3, openpyxl 2.5.14.)
Here's an interpreter session demonstrating the issue.
Python 3.7.2 (default, Dec 30 2018, 08:55:50) [Clang 10.0.0 (clang-1000.11.45.5)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import openpyxl >>> openpyxl.__version__ '2.5.14' >>> wb = openpyxl.Workbook() >>> ws = wb.active >>> import datetime >>> ws["A1"] = datetime.date.today() >>> type(ws["A1"].value) # expected to see datetime.datetime here <class 'datetime.date'> >>> wb.save("temp.xlsx") >>> wb = openpyxl.load_workbook("temp.xlsx") >>> ws = wb.active >>> type(ws["A1"].value) <class 'datetime.datetime'> # as expected
I'm not sure it's my place to put a priority on this, but the default priority of "major" seems like an overstatement, so I've made it "minor".