forked from Ev1si0n/wtv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinttools.py
87 lines (69 loc) · 2.34 KB
/
printtools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# coding=UTF-8
# -*-conding : gb2312 -*-
from tkinter import *
from tkinter.filedialog import askdirectory
import win32com.client
import win32api
import win32print
import time
import os
def selectPath():
path_ = askdirectory()
path.set(path_)
#read file count
file_name = os.listdir(path.get())
file_dir = [os.path.join(path.get(), x) for x in file_name]
count.set("file count = %d\n" % (len(file_dir)))
def startPritn():
print("start print %s" %path.get())
i = 0
file_name = os.listdir(path.get())
file_dirs = [os.path.join(path.get(), x) for x in file_name]
while i < len(file_dirs):
ext = os.path.splitext(file_dirs[i])[1]
if ext.startswith('.x'):
# excel
xlApp = win32com.client.Dispatch('Excel.Application')
xlApp.Visible = 0
xlApp.EnableEvents = False
xlApp.DisplayAlerts = False
xlBook = xlApp.Workbooks.Open(file_dirs[i])
xlApp.ActiveWorkbook.Sheets(1).PageSetup.Zoom = False
xlApp.ActiveWorkbook.Sheets(1).PageSetup.FitToPagesWide = 1
xlApp.ActiveWorkbook.Sheets(1).PageSetup.FitToPagesTall = 1
xlBook.PrintOut(1, 99, )
xlApp.quit()
else:
# word pdf txt
win32api.ShellExecute(
0,
"print",
file_dirs[i],
'/d:"%s"' % win32print.GetDefaultPrinter(),
".",
0
)
print(file_dirs[i])
time.sleep(1)
i = i + 1
root = Tk()
root.title('Print Tool')
width = 400
height = 280
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
root.geometry(alignstr)
root.resizable(width=True, height=True)
count = StringVar()
path = StringVar()
Label(root,text = "").pack()
Label(root,text = "Support batch printing of PDF, excel and word ",fg='red').pack(pady=10)
Label(root,text = "path:" ).pack()
Entry(root, textvariable = path).pack()
Button(root, text = "choose...", command = selectPath).pack(pady=10)
countLable = Label(root,textvariable = count,fg='blue').pack()
Button(root,text="start",command=startPritn).pack()
Label(root,text="author:zmy").pack()
Label(root,text="wechat:zmycloud").pack()
root.mainloop()