from openpyxl import load_workbook
wb = load_workbook("data.xlsx")
sheet = wb.active
print(sheet)
n = 0
for h in range(1,sheet.max_row+1):
for j in range(1, sheet.max_column+1):
if sheet.cell(row=h, column=j).value is None:
sheet.cell(h, j, n)
wb.save('data1.xlsx')
这种写法哪里有问题?显示错误:
AttributeError: 'MergedCell' object attribute 'value' is read-only
合并的单元格是不能写入的,写入合并单元格必须先写入一个单元格,再进行合并
循环遍历是不是None, value is None 改成 value is not None 就不会报错