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

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

  •  
  •   fanwei · 2016-04-03 21:25:08 +08:00 · 5267 次点击
    这是一个创建于 2936 天前的主题,其中的信息可能已经有所发展或是发生改变。
    找了半天也没找到好用的方法,结果找到个 perl 的包很靠谱( Spreadsheet::PrintExcelSheet )
    直接一句话, PrintIt( 'foo.xlsx', 'all' ) 方便好用

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

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

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

    就是 win32com ,搞定。
    (第一次用 python 搞 windows 专用的小程序。不熟悉 windows 这一套东西)
    lbp0200
        4
    lbp0200  
       2016-04-04 12:03:20 +08:00
    csv
    zhtw
        5
    zhtw  
       2016-05-18 10:08:56 +08:00
    请问一下楼主您怎么解决的啊?
    zhtw
        6
    zhtw  
       2016-05-18 14:08:14 +08:00
    xlApp = win32com.client.Dispatch('Excel.Application') #打开 EXCEL ,这里不需改动
    xlBook = xlApp.Workbooks.Open('dir') #将 dir 改为要处理的 excel 文件路径
    xlBook.PrintOut()
    xlBook.Close(SaveChanges=0) #完成 关闭保存文件
    del xlApp
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5565 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 03:15 · PVG 11:15 · LAX 20:15 · JFK 23:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.