我正在使用openpyxl读取excel工作表。它在迭代和分析行时抛出一个KeyError,因为openxml行元素没有reference属性('r')。它只有一个样式索引('s')和'customFormat'。在
Openxml spreadsheet attributes
如何读取此文件中的单元格?在
无论工作簿是否以只读方式打开,以及引用单元格时都会发生错误,因为它们都调用openpyxl.worksheet._reader.parse_row()
我不能共享excel工作簿,但是python代码非常简单。在
wb = load_workbook(filename)
ws = wb['Sheet1']
print(ws['A1'])
错误:
^{2}$从调试器:
row = {Element} <Element '{http://schemas.openxmlformats.org/spreadsheetml/2006/main}row' at 0x000002713782E9F8>
attrib = {dict} <class 'dict'>: {'s': '148', 'customFormat': '1'}
tag = {str} '{http://schemas.openxmlformats.org/spreadsheetml/2006/main}row'
tail = {NoneType} None
text = {NoneType} None
您必须降级到
openpyxl
版本2.5.14。在其中一个开发人员说(在
openpyxl
的2.6.x版本中,'r'
属性是必需的,即使OOXML规范说它是可选的。有关详细信息,请参见this issue opened on BitBucket。在相关问题 更多 >
编程相关推荐