Openpyxl cell.value different than expected

Issue #752 invalid
Kalub created an issue

I am having issues parsing data from my Excel file using openpyxl. In the excel file the cell is expected to have a value of "9/22/2016 8:00" in the cell format m/d/yyyy h:mm.

However when I extract the data from the cell and print it I receive a datetime.datetime object that is incorrect.

from openpyxl import load_workbook

wbk = load_workbook("file.xlsx")
sheet = wbk.get_sheet_by_name("Sheet 1")

value = sheet["E367"].value

print value

Outputs the following: 2016-09-22 07:59:59.999997 instead of 2016-09-22 08:00:00

What can I do to obtain the desired output? I tried to turn off data type guessing, and just using the internal value 42635.3333333 but I am unaware how to use that data to construct a datetime.datetime object.

Comments (3)

  1. Kalub reporter

    Where is the mailing list? As far as I know the internal serial value of 42635.3333333 should convert to 2016-09-22 08:00:00. Why is openpyxl interpretting it is 2016-09-22 07:59:59.999997?

    In Excel =TEXT("42635.3333333", "yyyy-mm-dd hh:mm:ss") evaluates to 2016-09-22 08:00:00

  2. Log in to comment