python批量设置多个Excel文件页眉页脚的脚本


Posted in Python onMarch 14, 2018

本文实例为大家分享了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 相关文章推荐
布同自制Python函数帮助查询小工具
Mar 13 Python
Python利用ElementTree模块处理XML的方法详解
Aug 31 Python
python中使用xlrd读excel使用xlwt写excel的实例代码
Jan 31 Python
python爬虫之urllib3的使用示例
Jul 09 Python
利用Python如何制作好玩的GIF动图详解
Jul 11 Python
win10下tensorflow和matplotlib安装教程
Sep 19 Python
python 列表转为字典的两个小方法(小结)
Jun 28 Python
Django对数据库进行添加与更新的例子
Jul 12 Python
django使用haystack调用Elasticsearch实现索引搜索
Jul 24 Python
python开头的coding设置方法
Aug 08 Python
python实现在多维数组中挑选符合条件的全部元素
Nov 26 Python
使用python编写一个语音朗读闹钟功能的示例代码
Jul 14 Python
浅谈python正则的常用方法 覆盖范围70%以上
Mar 14 #Python
Python使用matplotlib绘制多个图形单独显示的方法示例
Mar 14 #Python
Python使用matplotlib绘制余弦的散点图示例
Mar 14 #Python
使用Python从零开始撸一个区块链
Mar 14 #Python
Python使用matplotlib绘图无法显示中文问题的解决方法
Mar 14 #Python
Django中url的反向查询的方法
Mar 14 #Python
python ddt实现数据驱动
Mar 14 #Python
You might like
php array_flip() 删除数组重复元素
2009/01/14 PHP
PHP 调试工具Debug Tools
2011/04/30 PHP
LotusPhp笔记之:基于ObjectUtil组件的使用分析
2013/05/06 PHP
php计算给定时间之前的函数用法实例
2015/04/03 PHP
php中smarty变量修饰用法实例分析
2015/06/11 PHP
Swoole实现异步投递task任务案例详解
2019/04/02 PHP
客户端静态页面玩分页
2006/06/26 Javascript
List the Stored Procedures in a SQL Server database
2007/06/20 Javascript
编写Js代码要注意的几条规则
2010/09/10 Javascript
有关js的变量作用域和this指针的讨论
2010/12/16 Javascript
ASP.NET jQuery 实例5 (显示CheckBoxList成员选中的内容)
2012/01/13 Javascript
JS实现清除指定cookies的方法
2014/09/20 Javascript
浅谈JSON和JSONP区别及jQuery的ajax jsonp的使用
2014/11/23 Javascript
js实现进度条的方法
2015/02/13 Javascript
使用jquery动态加载Js文件和Css文件
2015/10/24 Javascript
详解Bootstrap glyphicons字体图标
2016/01/04 Javascript
jQuery简单实现tab选项卡切换效果
2016/06/20 Javascript
nodejs微信公众号支付开发
2016/09/19 NodeJs
vuex 中插件的编写案例解析
2019/06/10 Javascript
[04:16]DOTA2全国高校联赛16强抽签
2018/05/02 DOTA
python逐行读取文件内容的三种方法
2014/01/20 Python
python中使用enumerate函数遍历元素实例
2014/06/16 Python
python3生成随机数实例
2014/10/20 Python
Python下载网络文本数据到本地内存的四种实现方法示例
2018/02/05 Python
Keras 在fit_generator训练方式中加入图像random_crop操作
2020/07/03 Python
美国顶级防滑鞋:Shoes For Crews
2017/03/27 全球购物
美国顶级水上运动专业店:Marine Products
2018/04/15 全球购物
高性能钓鱼服装:Huk Gear
2019/02/20 全球购物
Viking Direct爱尔兰:办公用品和家具
2019/11/21 全球购物
外贸主管求职简历的自我评价
2013/10/23 职场文书
高中生家长会演讲稿
2014/01/14 职场文书
论文评语大全
2014/04/29 职场文书
幼儿园安全生产月活动总结
2014/07/05 职场文书
专项资金申请报告
2015/05/15 职场文书
2015年学校总务处工作总结
2015/05/19 职场文书
创业计划书之美容店
2019/09/16 职场文书