【发布时间】:2018-05-12 04:51:15
【问题描述】:
我正在尝试循环打印每列中的值的 excel 表。然后下到下一行,打印列的值,直到文件结束。
我的数据看起来像
Name email desc date
name1 email1 desc1 date1
name2 email2 desc2 date2
name3 email3 desc3 date3
wb = load_workbook('example.xlsx')
sheet = wb.get_sheet_by_name('Sheet1')
row_count = sheet.max_row -1
column_count = sheet.max_column
i = 1
while (i <= row_count):
for item in sheet.iter_cols():
#for row in sheet.iter_cols():
first_value = item[i]
print (first_value.value)
i+=1
我得到错误或元组索引超出范围,而且它也没有打印正确的数据。
first_value = item[i]
IndexError: tuple index out of range
在我得到超出范围错误之前使用上面的代码 name1, email2, desc3 作为输出,这显然是错误的,因为数据不在同一行中
【问题讨论】:
-
请提供您的完整代码和完整的错误信息。