我想使用openpyxl在Excel中创建一个循环,一切正常,更新我的列,但保存时我只评估最后一列的最后一个值。
from openpyxl import Workbook
x = 1
while True:
wb = Workbook()
ws = wb.active
ws['A' + str(x)] = 42
wb.save("test.xlsx")
y = input("dasdsa :")
if y == "ESC":
break
else:
x += 1
continue'
答案 0 :(得分:0)
将wb.save
移至您的if y
区块
from openpyxl import Workbook
x = 1
wb = Workbook()
while True:
ws = wb.active
ws['A' + str(x)] = 42
y = input("dasdsa :")
if y == "ESC":
wb.save("test.xlsx")
break
else:
x += 1
continue