import win32api
import win32print
# 要打印的文件
file_path = 'D://test.docx'
def printer_loading(filename):
open(filename, "r")
win32api.ShellExecute(
0,
"print",
filename,
'/d:"%s"' % win32print.GetDefaultPrinter(),
".",
0
)
printer_loading(file_path)
import win32com
from self import self
from win32com.client import Dispatch
file_open_path = 'test.docx'
self.xlApp = win32com.client.Dispatch('Word.Application')
self.xlApp.Visible = 0 # 后台运行,不显示
self.xlApp.DisplayAlerts = 0 # 不警告
self.doc = self.xlApp.Documents.Open(file_open_path)
# 打印
self.doc.PrintOut()