python批量设置多个Excel文件页眉页脚的脚本
本文实例为大家分享了python批量设置多个Excel文件页眉页脚的具体代码,供大家参考,具体内容如下
import os import openpyxl from openpyxl.worksheet.header_footer import _HeaderFooterPart xlsxFiles = (fn for fn in os.listdir('.') if fn.endswith('.xlsx')) for xlsxFile in xlsxFiles: wb = openpyxl.load_workbook(xlsxFile) for ws in wb.worksheets: # 设置首页与其他页不同 ws.HeaderFooter.differentFirst = True # 设置奇偶页不同 ws.HeaderFooter.differentOddEven = True # 设置首页页眉页脚 ws.firstHeader.left = _HeaderFooterPart('第一页左页眉', size=24, color='FF0000') ws.firstFooter.center = _HeaderFooterPart('第一页中页脚', size=24, color='00FF00') # 设置奇偶页页眉页脚 ws.oddHeader.right = _HeaderFooterPart('奇数页右页眉') ws.oddFooter.center = _HeaderFooterPart('奇数页中页脚') ws.evenHeader.left = _HeaderFooterPart('偶数页左页眉') ws.evenFooter.center = _HeaderFooterPart('偶数页中页脚') wb.save('new_'+xlsxFile)
来源:python小屋
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16