批量打印多个工作簿中的指定工作表
pip install xlwings
代码如下:
import os
import xlwings as xw
sheetname = input('输入指定工作表:')
filelist = os.listdir()
app = xw.App(visible=True, add_book=False)
for file in filelist:
if os.path.splitext(file)[1] == '.xlsx' or os.path.splitext(file)[1] == '.xls':
workbook = app.books.open(file)
for sheet in workbook.sheets:
try:
if sheet.name == sheetname:
print(sheet.name)
sheet.api.PrintOut()
break
except:
pass
app.quit()
os.system('pause')