推荐学习书目
› 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
liuxun349
V2EX  ›  Python

Python 操作 excel 的相关问题

  •  
  •   liuxun349 · May 9, 2018 · 5406 views
    This topic created in 3104 days ago, the information mentioned may be changed or developed.
    我对一已存在 excel 表进行读写操作,该表含多 sheet,保存之后,却只有最后一个 sheet。
    怎么才能对多 sheet 操作保存后,能达到想要的效果呢?
    大致写法:
    table = xlrd.open_workbook("test.xls", formatting_info=True)
    ctable = copy(table)
    p_sheet1 = ctable.get_sheet(0)
    p_sheet2 = ctable.get_sheet(1)
    .....对 sheet1,sheet2,读写操作....
    ctable.save("test.xls")
    15 replies  •  2018-05-10 19:50:29 +08:00
    myyou
    myyou
    May 9, 2018
    1
    保存的时候改名字
    bomb77
    bomb77
    May 9, 2018
    2
    xlutils
    liuxun349
    liuxun349
    OP
    May 9, 2018 via iPhone
    3
    @myyou 是改 sheet 的名字吗?文件名改是没有作用的
    liuxun349
    liuxun349
    OP
    May 9, 2018 via iPhone
    4
    @bomb77 求详解
    golmic
    golmic
    May 9, 2018 via Android
    5
    最关键的代码被你省略了。。。
    liuxun349
    liuxun349
    OP
    May 9, 2018 via iPhone
    6
    @golmic 啊?我就是使用 p_sheet1.write
    ()
    SingeeKing
    SingeeKing
    May 9, 2018 via iPhone
    7
    换成 xlutils

    BUT 为什么不用 openpyxl
    anguslg
    anguslg
    May 10, 2018
    8
    看了下文档, ctable 在 save 之前大概要先 add_sheet
    不过 更推荐用 pandas.DataFrame 处理
    catzh
    catzh
    May 10, 2018
    9
    同问,为什么不用 openpyxl ?
    myyou
    myyou
    May 10, 2018
    10
    from xlutils.copy import copy
    用这个 copy 可以在原有 Excel 修改
    jfry
    jfry
    May 10, 2018
    11
    建议用 openpyxl,而且如果需要制作报表的话可以看看 [toaco/tablereport: A python library for making table report.]( https://github.com/toaco/tablereport),完全兼容 openpyxl,哈哈,溜了溜了
    liuxun349
    liuxun349
    OP
    May 10, 2018
    12
    @SingeeKing
    @catzh
    因为之前不知道有 openpyxl,为了图快速解决问题,所以选择自己知道的。
    liuxun349
    liuxun349
    OP
    May 10, 2018
    13
    @myyou
    就是用的 xlutis.copy
    TGlivecoding
    TGlivecoding
    May 10, 2018
    14
    其实更推荐你用 http://xlsxwriter.readthedocs.io/ 现在用.xls 的不多了
    iblislsy
    iblislsy
    May 10, 2018
    15
    pandas 在保存 excel 的时候有一个参数 sheet_name, 了解一下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   691 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 22:21 · PVG 06:21 · LAX 14:21 · JFK 17:21
    ♥ Do have faith in what you're doing.