使用 Openpyxl 和 python3.5,我尝试使用下标从 Excel 工作表中获取第一行,但出现错误。
# 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
关于获得第一行,我也尝试过
第一个行 = 工作表。(行=1)
# 和
第一行 = 工作表.行[:1]
没有一个起作用。有什么建议或者 openpyxl 中不提供该功能吗?
我去过文档https://openpyxl.readthedocs.io/en/default/ https://openpyxl.readthedocs.io/en/default/但我发现没有任何东西足以索引和选择行
我终于在文档中找到了答案:
first_row = worksheet[1]
# worksheet[row_index_from_1]
这对我有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)