python openpyxl打印设置

import openpyxl

wb = openpyxl.Workbook()
ws = wb.active
# 1. 设置页面水平居中和竖向居中
ws.print_options.horizontalCentered = True
ws.print_options.verticalCentered = False
# 2.设置页眉页脚
ws.oddHeader.left.text = "Page &[Page] of &N"
ws.oddHeader.left.size = 14
ws.oddHeader.left.font = "'Tahoma',Bold" # 字体的设置方法见单元格的字体设置方法
ws.oddHeader.left.color = "CC3366"
# 3.设置行标题和列标题
ws.print_title_cols = 'A:B' # 设置列标题
ws.print_title_rows = '1:1' # 设置行标题
# 4.设置打印区域
ws.print_area = 'A1:F10'
# 5.设置纸张方向和纸张大小
ws.page_setup.orientation = ws.ORIENTATION_LANDSCAPE
ws.page_setup.paperSize = 9
'''
    ORIENTATION_PORTRAIT = 'portrait' #纵向
    ORIENTATION_LANDSCAPE = 'landscape' #横向
    # Paper size
    PAPERSIZE_LETTER = '1'
    PAPERSIZE_LETTER_SMALL = '2'
    PAPERSIZE_TABLOID = '3'
    PAPERSIZE_LEDGER = '4'
    PAPERSIZE_LEGAL = '5'
    PAPERSIZE_STATEMENT = '6'
    PAPERSIZE_EXECUTIVE = '7'
    PAPERSIZE_A3 = '8'
    PAPERSIZE_A4 = '9'
    PAPERSIZE_A4_SMALL = '10'
'''
# 6.设置页边距,单位为英寸1int=2.54cm
ws.page_margins.left = 0.5
ws.page_margins.right = 0.5
ws.page_margins.top = 0.5
ws.page_margins.bottom = 0.5
ws.page_margins.header=1.5
ws.page_margins.footer=1.0

wb.save('12.xlsx')
'''
1~5资料来源:
https://openpyxl.readthedocs.io/en/3.1.3/print_settings.html#headers-and-footers
6资料来源
自己查资料尝试出来的
可用的其他参数资料:https://blog.csdn.net/debrnr/article/details/124067362
'''
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值