I have a problem with a report I am reading with openpyxl. Sometimes cell formats in a file I receive are not correct, and instead of "10.03.2020" (cell format Date) I get "43900,88455" (cell format General).
I tried google, openpyxl documentation and StackOverflow but that did not bring me any closer to the solution. Would you be able to help and advise how to switch cell format to Short Date, please?
Below did not work, I tried many other ideas but still in a dead end. I need correct dates for other operations within this script.
def sanitizeDates(self):
# pass
for i in range(3, self.fileLength-1):
self.mainWs.cell(i, 4).number_format = 'dd/mm/yyyy'
self.mainWs.cell(i, 16).number_format = 'dd/mm/yyyy'
Copy comment: So I have tried
print("Cell (4) type is: " + str(type(self.mainWs.cell(i, 4).value)) + " and current value is " + str(self.mainWs.cell(i, 4).value)) print("Cell (16) type is: " + str(type(self.mainWs.cell(i, 16).value)) + " and current value is " + str(self.mainWs.cell(i, 16).value))
that results in Cell (4) type is:
<class 'datetime.datetime'>
and current value is2020-03-10 22:41:41
Cell (16) type is:<class 'float'>
and current value is43900.9475
Excel displays it as"General" = "43900,88455"