python - xlwings将xlsx打印为pdf

import os, xlwings as xw

app = xw.App(visible=False, add_book=False)  # visible操作是否可视化, add_book打开excel是否新建excel表
book = app.books.open(os.path.join(os.getcwd(), 'test.xlsx'))
sheet = book.sheets['sheet1']

sheet.api.ExportAsFixedFormat(0, os.path.join(os.getcwd(), 'test1.pdf'))  # 打印工作表操作
book.api.ExportAsFixedFormat(0, os.path.join(os.getcwd(), 'test2.pdf'))  # 打印整个工作簿操作

book.close()
app.quit()
posted @ 2024-10-27 11:33  wstong  阅读(35)  评论(0编辑  收藏  举报