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

python 在 window 下怎么打印 excel 啊?打印相关的资料很少的说

  •  
  •   fanwei · Apr 3, 2016 · 6492 views
    This topic created in 3835 days ago, the information mentioned may be changed or developed.
    找了半天也没找到好用的方法,结果找到个 perl 的包很靠谱( Spreadsheet::PrintExcelSheet )
    直接一句话, PrintIt( 'foo.xlsx', 'all' ) 方便好用

    网上 python 和打印相关的内容不是太多
    用 win32api.ShellExecute(0,'print','foo.xlsx','','',0)的话,反应很慢的说。关键是能完全隐藏打开 excel 的过程吗?最后一个参数怎么设置, excel 都会闪一下。

    或者 windows 下 python 有什么好方法结合 escpos 指令集的方法?
    我想方便订制和打印小票,折腾了半天了。求助!
    6 replies  •  2016-05-18 14:08:14 +08:00
    Kilerd
        1
    Kilerd  
       Apr 3, 2016
    就算你直接对一个 excel 文件 右键打印,都需要打开 excel 吧。
    zhuangzhuang1988
        2
    zhuangzhuang1988  
       Apr 3, 2016
    --> COM 试试。。
    fanwei
        3
    fanwei  
    OP
       Apr 3, 2016
    感谢回复!

    还是菜,对陌生语言没有想着去看源码。其实翻一下 Spreadsheet::PrintExcelSheet 简单明了。 http://cpansearch.perl.org/src/HAVI/Spreadsheet-PrintExcelSheet-0.02/lib/Spreadsheet/PrintExcelSheet.pm

    就是 win32com ,搞定。
    (第一次用 python 搞 windows 专用的小程序。不熟悉 windows 这一套东西)
    lbp0200
        4
    lbp0200  
       Apr 4, 2016
    csv
    zhtw
        5
    zhtw  
       May 18, 2016
    请问一下楼主您怎么解决的啊?
    zhtw
        6
    zhtw  
       May 18, 2016
    xlApp = win32com.client.Dispatch('Excel.Application') #打开 EXCEL ,这里不需改动
    xlBook = xlApp.Workbooks.Open('dir') #将 dir 改为要处理的 excel 文件路径
    xlBook.PrintOut()
    xlBook.Close(SaveChanges=0) #完成 关闭保存文件
    del xlApp
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2392 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:22 · PVG 20:22 · LAX 05:22 · JFK 08:22
    ♥ Do have faith in what you're doing.