我有一个excel文件,单元格C2上的值为20220831,单元格格式设置为日期。
当我尝试用openpyxl加载文件时,我会收到以下警告:
C:Usersjoaquim.MASCARELLAppDataLocalProgramsPythonPython310libsite-packagesopenpyxlworksheet_reader.py:211: UserWarning: Cell C2 is marked as a date but the serial value 20220831 is outside the limits for dates. The cell will be treated as an error.
warn(msg)
并且试图获得单元格值导致"0"#价值":
wb = xl.load_workbook(file)
sheet = wb["Sheet1"]
print(sheet["C2"].value)
>>#VALUE!
我想得到整数值"0";20220831";。
我可以传递什么参数来忽略类型标记并简单地返回存储在xml中的值吗?
一种技巧,只需删除这一行
value = "#VALUE!"
在C:\Users\joaquim.MASCARELL\AppData\Local\Programs\Python310\lib\site packages\openpyxl\worksheet_reader.py 中
except (OverflowError, ValueError):
msg = f"""Cell {coordinate} is marked as a date but the serial value {value} is outside the limits for dates. The cell will be treated as an error."""
warn(msg)
data_type = "e"
#value = "#VALUE!"