我想在Python中创建一个列循环

时间:2017-12-27 09:31:53

标签: python excel loops openpyxl

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

1 个答案:

答案 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