赞
踩
转发https://blog.csdn.net/weixin_48160417/article/details/125395557
在此记录自己使用
import xlwings as xw
app = xw.App(visible=False, add_book=False)
workbook = app.books.open(‘各月销售数量表.xlsx’)
workbook.api.PrintOut(Copies=2, ActivePrinter=‘DESKTOP-HP01’, Collate=True) # 打印工作簿中的所有工作表,这里指定打印份数为两份,打印机为“DESKTOP-HP01”
workbook.close()
app.quit()
import xlwings as xw
app = xw.App(visible=False, add_book=False)
workbook = app.books.open(‘各月销售数量表.xlsx’)
worksheet = workbook.sheets[‘1月’]
worksheet.api.PrintOut(Copies=2, ActivePrinter=‘DESKTOP-HP01’, Collate=True)
workbook.close()
app.quit()
from pathlib import Path
import xlwings as xw
folder_path = Path(‘各地区销售数量’)
file_list = folder_path.glob(‘.xls’)
app = xw.App(visible=False, add_book=False)
for i in file_list:
workbook = app.books.open(i)
workbook.api.PrintOut(Copies=1, ActivePrinter=‘DESKTOP-HP01’, Collate=True)
workbook.close()
app.quit()
from pathlib import Path
import xlwings as xw
folder_path = Path(‘各地区销售数量’)
file_list = folder_path.glob(‘.xls’)
app = xw.App(visible=False, add_book=False)
for i in file_list:
workbook = app.books.open(i)
worksheet = workbook.sheets[‘销售数量’]
worksheet.api.PrintOut(Copies=1, ActivePrinter=‘DESKTOP-HP01’, Collate=True)
workbook.close()
app.quit()
import xlwings as xw
app = xw.App(visible=False, add_book=False)
workbook = app.books.open(‘销售表.xlsx’)
worksheet = workbook.sheets[‘总表’]
area = worksheet.range(‘A1:I10’)
area.api.PrintOut(Copies=1, ActivePrinter=‘DESKTOP-HP01’, Collate=True)
workbook.close()
app.quit()
import xlwings as xw
app = xw.App(visible=False, add_book=False)
workbook = app.books.open(‘销售表.xlsx’)
worksheet = workbook.sheets[‘总表’]
worksheet.api.PageSetup.Zoom = 80 # 按工作表原始大小的80%进行打印
worksheet.api.PrintOut(Copies=1, ActivePrinter=‘DESKTOP-HP01’, Collate=True)
workbook.close()
app.quit()
import xlwings as xw
app = xw.App(visible=False, add_book=False)
workbook = app.books.open(‘各月销售数量表.xlsx’)
worksheet = workbook.sheets[‘1月’]
worksheet.api.PageSetup.CenterHorizontally = True # 调整工作表在纸张上的水平位置
worksheet.api.PageSetup.CenterVertically = True # 调整工作表在纸张上的垂直位置
worksheet.api.PrintOut(Copies=1, ActivePrinter=‘DESKTOP-HP01’, Collate=True)
workbook.close()
app.quit()
import xlwings as xw
app = xw.App(visible=False, add_book=False)
workbook = app.books.open(‘各月销售数量表.xlsx’)
worksheet = workbook.sheets[‘1月’]
worksheet.api.PageSetup.PrintHeadings = True
worksheet.api.PrintOut(Copies=1, ActivePrinter=‘DESKTOP-HP01’, Collate=True)
workbook.close()
app.quit()
import xlwings as xw
app = xw.App(visible=False, add_book=False)
workbook = app.books.open(‘销售表.xlsx’)
worksheet = workbook.sheets[‘总表’]
worksheet.api.PageSetup.PrintTitleRows = ‘$1:$1’ # 将工作表第一行设置为要重复打印的标题行
worksheet.api.PageSetup.Zoom = 55 # 按工作表原始大小的55%进行打印
worksheet.api.PrintOut(Copies=1, ActivePrinter=‘DESKTOP-HP01’, Collate=True)
workbook.close()
app.quit()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。