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

openpyxl load/save workbook

  •  
  •   mybdye · 2021-03-19 15:17:21 +08:00 · 1368 次点击
    这是一个创建于 1132 天前的主题,其中的信息可能已经有所发展或是发生改变。
    头大!
    接触 python 小半月,写了个工具用于将 txt 数据解析分组然后填入 xlsx 模板,但是这个打开和保存的时间也太长了 8,模板有几兆,里面若干曲线图和透视表
    https://ftp.bmp.ovh/imgs/2021/03/6cdd5e4d7b7b2adc.png

    这个是本地机器配置,执行过程 CPU 100%
    https://ftp.bmp.ovh/imgs/2021/03/b9d2e3ab55fc8c9a.png
    第 1 条附言  ·  2021-03-19 19:38:40 +08:00
    t_read_txt_start: 2021-03-19 14:43:37.563969

    #load
    t_load_excel_start: 2021-03-19 14:43:37.570081
    t_load_excel_end: 2021-03-19 14:44:08.503543

    #write
    t_write_excel-0-0: 2021-03-19 14:44:08.503633
    .....
    t_write_excel-4-0: 2021-03-19 14:44:08.547833

    #save
    t_save_excel_start: 2021-03-19 14:44:08.547841
    t_save_excel_end: 2021-03-19 14:44:33.884677

    写入成功!
    总耗时 t_1-t_0=: 0:00:56.320748
    第 2 条附言  ·  2021-03-20 01:49:42 +08:00
    #换 xlwings,改多行写入,速度马上起飞🥳

    le_C_reportIn_DropEvent! len: 66
    le_C_reportName_DropEvent! len: 15
    Button_C_go Clicked

    #load
    t_load_excel_start: 2021-03-20 01:30:57.472503
    t_load_excel_end: 2021-03-20 01:31:00.083184

    #write
    t_write_sheet_0 2021-03-20 01:31:00.083241
    t_write_sheet_1 2021-03-20 01:31:01.931310
    ...
    t_write_sheet_13 2021-03-20 01:31:19.245457
    t_write_sheet_14 2021-03-20 01:31:20.544629

    #save
    t_save_excel_start: 2021-03-20 01:31:21.852513
    t_save_excel_end: 2021-03-20 01:31:24.656955

    写入成功!
    耗时: 0:00:32.130284
    9 条回复    2021-03-20 13:11:36 +08:00
    ch2
        1
    ch2  
       2021-03-19 17:55:23 +08:00
    非常正常,它导出就这样慢
    mybdye
        2
    mybdye  
    OP
       2021-03-19 17:58:45 +08:00
    @ch2 #1 试了下 xlwings,open/save 快了点,就是逐行写数据蜗牛一样
    chenqh
        3
    chenqh  
       2021-03-19 18:08:20 +08:00
    @mybdye py 就是这么慢呀,我当初用 openpyxl 导出一 W 条数据直接几分钟
    Vegetable
        4
    Vegetable  
       2021-03-19 18:10:23 +08:00
    mybdye
        5
    mybdye  
    OP
       2021-03-19 19:33:45 +08:00
    @Vegetable #4 👌,我都去看下,选最优的
    BeautifulSoap
        6
    BeautifulSoap  
       2021-03-19 20:10:08 +08:00
    你既然不是要做成网络服务供一堆人用的话,那就转投 xlwings,让速度飞起来
    mybdye
        7
    mybdye  
    OP
       2021-03-20 01:51:57 +08:00
    @BeautifulSoap #6 研究了下,对于目前的需求还是 xlwings 香
    chenqh
        8
    chenqh  
       2021-03-20 12:09:46 +08:00
    xlwings 最多可以多少行,10W 行数据可以吗?如果可以的话,我也换 xlwings 了
    mybdye
        9
    mybdye  
    OP
       2021-03-20 13:11:36 +08:00
    @chenqh #8 刚接触 xw,还在研究。没查到有限制,可以的话你先试试。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3271 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 12:53 · PVG 20:53 · LAX 05:53 · JFK 08:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.