openpyxl库 excel工作表中问问这串代码如果想要将指定一列的指定几行下的数据进行条件筛选该怎么加
for col in ws_new.columns:
for v in col: if v.value=='期中作业': qz_row=v.row qz_column=v.column # print(v.row,v.column)
print(qz_row,qz_column)
for i in range(qz_row+1,ws_new.max_row+1):
if ws_new.cell(i,qz_column).value != None:
print(type(ws_new.cell(i,qz_column).value),ws_new.cell(i,qz_column).value)
可以在上述代码中加入一个条件判断,如果符合筛选条件就输出。
for col in ws_new.columns:
for v in col:
if v.value=='期中作业':
qz_row=v.row
qz_column=v.column
print(qz_row,qz_column)
for i in range(qz_row+1,ws_new.max_row+1):
if ws_new.cell(i,qz_column).value != None and ws_new.cell(i,qz_column).value > 80:
print(ws_new.cell(i,qz_column).value)
for i in range(qz_row+1,ws_new.max_row+1):
if ws_new.cell(i,qz_column).value != None and ws_new.cell(i,qz_column).value == "优":
print(ws_new.cell(i,qz_column).value)