简体   繁体   English

使用xlwt将xls打印到纸张

[英]Using xlwt to print xls to paper

So, I am using the xlwt and xlrd modules in python to write to a XLS document. 因此,我在python中使用xlwt和xlrd模块写入XLS文档。 What I am trying to do now, is to have this useless file be printed out on paper, old school style, but searching for "print out on paper" (or the like) just gives you the wrong results. 我现在想要做的是,将这种无用的文件打印在纸上,这是旧式,但是搜索“纸上打印”(或类似内容)只会给您错误的结果。 Can anyone help me? 谁能帮我?

here is the code: 这是代码:

import xlwt
import xlrd
from xlutils.copy import copy
from tkinter import *


def test():
    print(ent.get())

    rb = xlrd.open_workbook("test.xls")
    wb = copy(rb)
    w_sheet = wb.get_sheet(0)
    w_sheet.write(0,1,ent.get())
    fr = w_sheet.col(0)
    fr.width = 256 * 20
    wb.save("test.xls")

vindue = Tk()

but = Button(vindue, text="Click", command=test)
but.pack()

ent = Entry(vindue)
ent.pack()

vindue.mainloop()

Found the solution my self. 找到了我自己的解决方案。

import win32api
import win32print

filename = "test.xlsx"
    open(filename, "r")
    win32api.ShellExecute(
        0,
        "print",
        filename,
        '/d:"%s"' % win32print.GetDefaultPrinter(),
        ".",
        0
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM