突然出现错误-> TypeError:“ NoneType”和“ int”的实例之间不支持“ <”

时间:2019-04-01 04:48:52

标签: python openpyxl

我一直在成功运行下面的代码,但是今天突然在下面出现错误

在我看来,“ r [0] .value”返回为Nonetype,但实际上在excel工作表中,第一列(A列)中有数字

任何人都可以帮助我理解为什么我会获得Nonetype吗?

from openpyxl import load_workbook

load_wb = load_workbook("abc.xlsx")
load_ws = load_wb.active

for r in load_ws.rows:
    str1 = str(r[3].value)
    row_index = r[0].value
    for k in load_ws.rows:
        if (str(k[1].value).find(str1) != -1):
            load_ws.cell(row=row_index, column=5).value = str(k[2].value)

load_wb.save("abc_result.xlsx")
load_wb.close()

错误:

Traceback (most recent call last):   File "C:\Python_Scripts\excel_test1.py", line 11, in <module>
    load_ws.cell(row=row_index, column=5).value = str(k[2].value)   File "C:\Program Files (x86)\Python3\lib\site-packages\openpyxl\worksheet\worksheet.py", line 236, in cell
    if row < 1 or column < 1: TypeError: '<' not supported between instances of 'NoneType' and 'int'

0 个答案:

没有答案