我想使用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'
将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