Can I disable openpyxl from automatically parsing strings to datetime?

a 夏天 提交于 2019-12-10 23:29:43

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/44337032/can-i-disable-openpyxl-from-automatically-parsing-strings-to-datetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!