叶子小小的,碧绿碧绿的,花儿小小的,好可爱。紫红色的玫瑰花在风中翩翩起舞,玫瑰花树枝上还有调皮又可爱的小刺,你可要当心哦!你看,那个大仙人球旁围着8个小仙人球,好像一家人聚在一起,多欢快呀!
本文实例为大家分享了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小屋
以上就是python批量设置多个Excel文件页眉页脚的脚本。爱上你,等于爱上了寂寞。更多关于python批量设置多个Excel文件页眉页脚的脚本请关注haodaima.com其它相关文章!