Python Openpyxl:can';似乎没有正确的语法来解释我所说的';我正在做(向下读下一个单元格)
这是我的密码。我只是试着打开一个电子表格(目前只有第一列中的信息),读取第一个单元格,打印信息,然后沿着行循环返回到顶部,向下读取下一个单元格。我做错了什么Python Openpyxl:can';似乎没有正确的语法来解释我所说的';我正在做(向下读下一个单元格),python,excel,openpyxl,Python,Excel,Openpyxl,这是我的密码。我只是试着打开一个电子表格(目前只有第一列中的信息),读取第一个单元格,打印信息,然后沿着行循环返回到顶部,向下读取下一个单元格。我做错了什么 import openpyxl wb = openpyxl.load_workbook('students2.xlsx') ws = wb.active PrintNext = True #Starts my while statement while True : for i in range(1,300):
import openpyxl
wb = openpyxl.load_workbook('students2.xlsx')
ws = wb.active
PrintNext = True #Starts my while statement
while True :
for i in range(1,300): #I think this is where I'm having an issue?
for j in range(1,2):
StudentID = ws.cell(row=i+1, column=j).value
print(StudentID)
PrintNext = False #This gets it to move on from my while
pass
PrintNext = True #This is to get it to go back to my while
print(StudentID) #This is to test that it has the next cell down
我在这里的答案帮助下找到了解决方案,但我找到了一个更好的解决方案
将这些设置为变量:
for i in range(RowX,RowY):
for j in range(ColX,ColY):
StudentID = ws.cell(row=i+1, column=j).value
这样,您所做的任何更改(“例如,RowX=RowX+1”)都会在下次更新“for”语句时反映出来 您可以使用该方法。这是我最后得到的代码:
print(StudentID)PrintNext=False class AbstractCell(ABC):@abstractmethod def offset(self,row=1,column=0):pass
我不理解该代码。最好是编辑你的原始问题。收到!更新!