缺少reference属性时,Openpyxl无法读取行

2024-09-25 00:22:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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

Tags: orghttpwsmain错误elementexcelschemas