初学,搞不懂哪里出了问题
import openpyxl
from openpyxl import Workbook, load_workbook
wb = load_workbook('mmm.xlsx')
ws = wb.active
for j in range(2, 7):
hSum = 0
for i in range(2, 11):
if ws.cell(i, 2).value == '小学':
hSum=hSum+ws.cell(i, j + 1).value
#这句总是错误提示。unsupported operand type(s) for +: 'int' and 'NoneType'
else:
hSum = 0
ws.cell(i, j + 1).value = hSum
The value of
ws.cell(i, j + 1).value
maybe not defined orNone
, so not support+
withNoneType
, likehSum + ws.cell(i, j + 1).value
If no value for a cell, you got
None
, check if the (row, col) is correct for the cells with values.需要类型转换,表格无值给了None,数字与None类型不能直接运算