首页 > 解决方案 > 无法遍历列表 - Openpyxl

问题描述

我无法遍历数据行(我保存到列表中)。

下面是示例代码

Timelist = []
for row_cells in sheetname.iter_rows(min_col=1,max_col=6,min_row=2):
             Timelist = row_cells[1].value

for x in Timelist:
    print(x)

我想遍历该列的行值(在本例中为第 1 列)

标签: pythonopenpyxl

解决方案


您可能希望将值附加到Timelistfor 循环内的列表中,而不是分配,以便以后能够对其进行迭代以进行打印x

Timelist = []

for row_cells in sheetname.iter_rows(min_col=1,max_col=6,min_row=2):
    Timelist.append(row_cells[1].value) # <--- append here

for x in Timelist:
    print(x)

推荐阅读