wb = load_workbook('test.xlsx')
ws = wb.active
x = 0
for sheet in ws:
for cell in sheet[0:]:
if 'Attribute' in cell.value:
x = x + 1
print(x)
ws.delete_cols(x)
else:
x = x + 1
wb.save('new_test.xlsx')我收到以下错误文件"d:\Temp\Python\Excel_Test.py",第33行,在cell.value中的if 'Attribute‘中: TypeError:类型为'NoneType’的参数不可迭代
发布于 2022-03-10 09:01:29
可能不是一个最佳解决方案,但它有效:
import openpyxl
wb = openpyxl.load_workbook('file_name.xlsx')
ws = wb.active
x = ws.max_row
y = ws.max_column
print(f"maxrow: {x}, maxcol: {y}")
for row in range(2, x+1):
for col in range(1, y+1):
#print(ws.cell(row=row, column=col).value)
if 'Attribute' in str(ws.cell(row=row, column=col).value):
ws.delete_cols(col)
wb.save('file_name.xlsx')https://stackoverflow.com/questions/71420050
复制相似问题