如何在 openpyxl 中只追加一次?
How to append only once in openpyxl?
虽然我理解代码存在的问题,但我不知道如何更正它。 append
正在写入 8 行。恰好有 8 个单元格已被检查,因此它写入 8 行。
for row in ws.iter_rows():
for cell in row:
if i == cell.value:
print("found match")
else:
y=[]
y.append(i)
ws.append(y)
wb.save("Trying web.xlsx")
因为在 python 中,缩进很重要。
for row in ws.iter_rows():
y=[]
for cell in row:
if i == cell.value:
print("found match")
else:
y.append(i)
ws.append(y)
wb.save("Trying web.xlsx")
虽然我理解代码存在的问题,但我不知道如何更正它。 append
正在写入 8 行。恰好有 8 个单元格已被检查,因此它写入 8 行。
for row in ws.iter_rows():
for cell in row:
if i == cell.value:
print("found match")
else:
y=[]
y.append(i)
ws.append(y)
wb.save("Trying web.xlsx")
因为在 python 中,缩进很重要。
for row in ws.iter_rows():
y=[]
for cell in row:
if i == cell.value:
print("found match")
else:
y.append(i)
ws.append(y)
wb.save("Trying web.xlsx")