V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
pharaoh21c
V2EX  ›  Python

xlwt 一直显示 AttributeError: 'Sheet' object has no attribute 'write'

  •  
  •   pharaoh21c · 2018-07-06 11:23:17 +08:00 · 14398 次点击
    这是一个创建于 2113 天前的主题,其中的信息可能已经有所发展或是发生改变。
    python 版本 3.6,windows7,我已经安装了 xlrd 和 xlwt 模块,为何在执行下方代码时一直显示:
    AttributeError: 'Sheet' object has no attribute 'write'

    多谢高手指点!

    代码如下:
    "
    import xlrd
    import xlwt

    bo1=xlrd.open_workbook(r'C:\extest01.xlsx')
    she1=bo1.sheets()[0]
    she1.write(0,10,"string")
    "
    4 条回复    2018-07-06 21:46:15 +08:00
    saulshao
        1
    saulshao  
       2018-07-06 15:58:57 +08:00
    你那个是读...你都没用 xlwt 这个模块,只是引入了一下,读一下文档吧。
    我建议换用那个新版的,好像叫 openxl 还是啥来着
    pharaoh21c
        2
    pharaoh21c  
    OP
       2018-07-06 17:47:06 +08:00
    @saulshao 谢谢!我百度了很久,好像就是用这个语法的,搞不懂。另外那个是说 openpyxl 么,我也在同步尝试。。。
    saulshao
        3
    saulshao  
       2018-07-06 18:00:49 +08:00
    你不能用 xlrd.open,应该用 xlwt.open 或者啥的。
    换句话说,前面那个是只读打开,后面那个打开的文件才会有写方法
    相关的文档有完整的实例
    pharaoh21c
        4
    pharaoh21c  
    OP
       2018-07-06 21:46:15 +08:00
    @saulshao 多谢指点~~~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1341 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 17:35 · PVG 01:35 · LAX 10:35 · JFK 13:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.