首页 > 其他 > 详细

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

时间:2019-03-19 00:11:25      阅读:761      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

解决方案:

   因为新版本的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>

 

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

原文:https://www.cnblogs.com/zhmiao/p/10556061.html

(0)
(2)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!