I want to use double for loop in openpyxl

僤鯓⒐⒋嵵緔 提交于 2019-12-11 16:10:34

问题


I'm making a program that organizes revenues by year and quarter.

retyear() list type, Source file data  with information of year = [2009, 2017, 2019, ,2020, 2021, 2022, 2099]
shtcount=len(retyear)
shtcount2=(len(retyear)*5)

---------------------------------problem code--------------------------------------

wb2 = openpyxl.load_workbook("/Users/GiraffeMan/Desktop/02.xlsx", data_only=True)
file = "/Users/GiraffeMan/Desktop/02.xlsx"
ws2 = wb2['Summary']
for t in range(3, shtcount2, 5):
    for p in range(0, shtcount):
    print(retyear[p])
    ws2 = wb2.active
        ws2.cell(row=2, column=t, value="%dQ1" % retyear[p])
        ws2.cell(row=2, column=t+1, value="%dQ2" % retyear[p])
        ws2.cell(row=2, column=t+2, value="%dQ3" % retyear[p])
        ws2.cell(row=2, column=t+3, value="%dQ4" % retyear[p])
        ws2.cell(row=2, column=t+4, value="%dY Total" % retyear[p])
    wb2.save(file)
  • code : print(retyear[p]) -> Works Fine!
  • code : double for loop -> Work Strangely...

double for loop only extracts the number 2099... Why?

来源:https://stackoverflow.com/questions/58082088/i-want-to-use-double-for-loop-in-openpyxl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!