1.支持批量打印excel、word、pdf、txt文件
2.支持excel多个sheet
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
网友评论