简体   繁体   中英

Using xlwt to print xls to paper

So, I am using the xlwt and xlrd modules in python to write to a XLS document. 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
    )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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