openpyxl使用sheet.rows或sheet.columns报TypeError: 'generator' object is not subscriptable解决方式


 

解决方案:

   因为新版本的openpyxl使用rows或者columns返回一个生成器所以可以使用List来解决报错问题

    

>>> sheet.columns[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'generator' object is not subscriptable
>>> list(sheet.columns)[0]
(<Cell Sheet1.A1>, <Cell Sheet1.A2>, <Cell Sheet1.A3>, <Cell Sheet1.A4>
>>> list(sheet.columns)[1]
(<Cell Sheet1.B1>, <Cell Sheet1.B2>, <Cell Sheet1.B3>, <Cell Sheet1.B4>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM