Reputation: 6241
I'm having simple excel files with various timstamp formats written as strings.
There is a build in feature in openpyxl to automatically convert what seems like a date to a datetime object.
My question is simple, how can I take the raw string as it was inserted to the excel file by the user, without intervention of openpyxl
.
I want to do my own format testings using a function that tries various calls to datetime.strptime
myself.
Loading the excel is done by me like this:
import openpyxl
ex = openpyxl.load_workbook('/path/to/file.xls')
worksheet = ex.active
In case needing to iterate over rows I'm using worksheet.iter_rows
method
Upvotes: 4
Views: 1494
Reputation: 19507
You're assumption is incorrect: openpyxl does not convert strings unless you ask it to by setting guess_types=True
. Excel treats the values as datetime objects by setting the number format and internally converting them to serials with an epoch of 1899-12-30.
Upvotes: 3