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

Python 如何将如下文本内容导入 excel

  •  
  •   fsckzy · Jan 5, 2018 · 3831 views
    This topic created in 3239 days ago, the information mentioned may be changed or developed.
    源文件如下:
    格式为:
    ip
    user1
    user2
    user3
    user4
    ....



    我想要的是这样:
    user1
    user2
    ip user3
    user4
    user5


    请问下有啥好方法吗?
    6 replies  •  2018-01-05 12:36:20 +08:00
    wellsc
    wellsc
    Jan 5, 2018
    1
    花式 split
    860670496
    860670496
    Jan 5, 2018
    2
    没看明白,是图片里那样的 A 列的 IP 单元格合并成一个吗?那样的话 xlwt 里有对应的方法,记得是 merge
    随便搜了一个文章: https://www.jianshu.com/p/4e39444d5ebc
    涉及格式的问题我一般都用 vba 再写个脚本再处理一下,比在 python 里折腾方便多了,又不用装环境。你这个需求大概 10 行左右就能解决
    superhan
    superhan
    Jan 5, 2018 via Android
    3
    如果以后经常用 ansible 那你看看 ansible callback 吧
    EyreFree
    EyreFree
    Jan 5, 2018
    4
    唔,之前用 C 艹 做类似需求的时候发现一个小技巧,把你的内容直接输出成纯文本,然后后缀设为 .xls 即可,用 Excel 打开会自动识别...

    具体的忘了,大概是列之间 \t 分割,行之间 \n 分割,反正不是很复杂...

    原理大概可参考这一篇博文: http://www.cnblogs.com/zhoujinyi/archive/2013/05/07/3064785.html
    EyreFree
    EyreFree
    Jan 5, 2018
    5
    哦,发现好像不满足楼主的需求,无视上面一条吧...
    dangyuluo
    dangyuluo
    Jan 5, 2018
    6
    合并单元格
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1061 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 23:04 · PVG 07:04 · LAX 15:04 · JFK 18:04
    ♥ Do have faith in what you're doing.