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
shawnma
V2EX  ›  Python

[小白求助] Python 操作 Excel 的小问题

  •  
  •   shawnma · 2020-04-03 18:53:39 +08:00 via iPhone · 1836 次点击
    这是一个创建于 1482 天前的主题,其中的信息可能已经有所发展或是发生改变。
    大佬们,怎么用 openpyxl 模块实现在同一个单元格内主动换行写入?
    4 条回复    2020-04-03 22:56:53 +08:00
    renmu
        1
    renmu  
       2020-04-03 19:06:13 +08:00 via Android
    字符串里加一个\n 试试?
    shawnma
        2
    shawnma  
    OP
       2020-04-03 19:35:03 +08:00 via iPhone
    @renmu 非常感谢回答,试过了,木有用…
    renmu
        3
    renmu  
       2020-04-03 19:50:06 +08:00 via Android   ❤️ 1
    我找到了这个,你可以试试,可以在 Stack Overflow 搜这个:Writing multi-line strings into cells using openpyxl 。
    我发不出来链接。
    worksheet.cell('A1').style.alignment.wrap_text = True
    worksheet.cell('A1').value = "Line 1\nLine 2\nLine 3"
    shawnma
        4
    shawnma  
    OP
       2020-04-03 22:56:53 +08:00 via iPhone
    @renmu 多谢指点,问题解决了~~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1014 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:59 · PVG 03:59 · LAX 12:59 · JFK 15:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.