问题
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