Openpyxl如何通过索引从工作表中获取行 [英] Openpyxl How to get row from worksheet by index
问题描述
使用Openpyxl和python3.5,我尝试使用下标从excel工作表中获取第一行,但我是一个错误。
Using Openpyxl and python3.5, I tried getting the first row from an excel worksheet using a subscript but I an error.
# after getting filename
# after loading worksheet
# to get the first row of the worksheet
first_row = worksheet.rows[0]
# I get
Traceback (most recent call last):
File "<pyshell#54>", line 1, in <module>
first_row = phc_th_sheet.rows[1]
TypeError: 'generator' object is not subscriptable
关于获得第一行,我还尝试了
first_row = worksheet。(row = 1)
#和
first_row = worksheet.rows [:1]
In relation to getting the first row, I've also tried first_row = worksheet.(row=1) # and first_row = worksheet.rows[:1]
无效。任何建议或openpyxl中没有的功能?
我去过 https://openpyxl.readthedocs.io/en / default / 但我发现没有什么有用的索引和选择行
None worked. Any suggestions or is the feature not available in openpyxl? I've been to the documentation at https://openpyxl.readthedocs.io/en/default/ but I found nothing helpful enough to index and select rows
推荐答案
我终于找到了答案文档:
I finally found the answer in the documentation:
first_row = worksheet.rows[1]
# worksheet.rows[row_index_from_1]
这对我有用。
这篇关于Openpyxl如何通过索引从工作表中获取行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!