V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Mar 19, 2021 · 1889 views
    This topic created in 1865 days ago, the information mentioned may be changed or developed.
    头大!
    接触 python 小半月,写了个工具用于将 txt 数据解析分组然后填入 xlsx 模板,但是这个打开和保存的时间也太长了 8,模板有几兆,里面若干曲线图和透视表
    https://ftp.bmp.ovh/imgs/2021/03/6cdd5e4d7b7b2adc.png

    这个是本地机器配置,执行过程 CPU 100%
    https://ftp.bmp.ovh/imgs/2021/03/b9d2e3ab55fc8c9a.png
    Supplement 1  ·  Mar 19, 2021
    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
    Supplement 2  ·  Mar 20, 2021
    #换 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 replies    2021-03-20 13:11:36 +08:00
    ch2
        1
    ch2  
       Mar 19, 2021
    非常正常,它导出就这样慢
    mybdye
        2
    mybdye  
    OP
       Mar 19, 2021
    @ch2 #1 试了下 xlwings,open/save 快了点,就是逐行写数据蜗牛一样
    simple2025
        3
    simple2025  
       Mar 19, 2021
    @mybdye py 就是这么慢呀,我当初用 openpyxl 导出一 W 条数据直接几分钟
    Vegetable
        4
    Vegetable  
       Mar 19, 2021
    mybdye
        5
    mybdye  
    OP
       Mar 19, 2021
    @Vegetable #4 👌,我都去看下,选最优的
    BeautifulSoap
        6
    BeautifulSoap  
       Mar 19, 2021
    你既然不是要做成网络服务供一堆人用的话,那就转投 xlwings,让速度飞起来
    mybdye
        7
    mybdye  
    OP
       Mar 20, 2021
    @BeautifulSoap #6 研究了下,对于目前的需求还是 xlwings 香
    simple2025
        8
    simple2025  
       Mar 20, 2021
    xlwings 最多可以多少行,10W 行数据可以吗?如果可以的话,我也换 xlwings 了
    mybdye
        9
    mybdye  
    OP
       Mar 20, 2021
    @chenqh #8 刚接触 xw,还在研究。没查到有限制,可以的话你先试试。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   934 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 21:06 · PVG 05:06 · LAX 14:06 · JFK 17:06
    ♥ Do have faith in what you're doing.