Python openpyxl 遍历所有sheet 查找特定字符串的方法


Posted in Python onDecember 10, 2018

如下所示:

from openpyxl import workbook
from openpyxl import load_workbook
from openpyxl import worksheet

def find_false_in_sheet(sheet):
 for column in sheet.iter_cols():
  for cell2 in column:
   if cell2.value is not None:
    # print cell2.value
    # print type(cell2.value)
    info2 = cell2.value.find('false')
    if info2 == 0:
     print cell2
     print cell2.value

def find_false_in_xlsx(file_name):
 print file_name
 wb = load_workbook(file_name)
 all_sheets = wb.get_sheet_names()
 print(all_sheets)

 for i in range(len(all_sheets)):
  sheet = wb.get_sheet_by_name(all_sheets[i])
  print (sheet.title + ': max_row: ' + str(sheet.max_row) + ' max_column: ' + str(sheet.max_column))
  find_false_in_sheet(sheet)

# start
find_false_in_xlsx("test.xlsx")


# for row in sheet.iter_rows():
#  for cell in row:
#   if cell.value is not None:
#    info = cell.value.find('BB')
#    if info == 0:
#     print cell.value

以上这篇Python openpyxl 遍历所有sheet 查找特定字符串就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python格式化字符串实例总结
Sep 28 Python
使用Python中PDB模块中的命令来调试Python代码的教程
Mar 30 Python
python中的错误处理
Apr 10 Python
python使用opencv进行人脸识别
Apr 07 Python
python sys.argv[]用法实例详解
May 25 Python
python排序函数sort()与sorted()的区别
Sep 18 Python
Python 实现取矩阵的部分列,保存为一个新的矩阵方法
Nov 14 Python
python3+selenium实现126邮箱登陆并发送邮件功能
Jan 23 Python
python读取Kafka实例
Dec 23 Python
解决Jupyter Notebook使用parser.parse_args出现错误问题
Apr 20 Python
python 元组的使用方法
Jun 09 Python
浅谈keras 模型用于预测时的注意事项
Jun 27 Python
使用pandas实现csv/excel sheet互相转换的方法
Dec 10 #Python
python得到一个excel的全部sheet标签值方法
Dec 10 #Python
解决pandas .to_excel不覆盖已有sheet的问题
Dec 10 #Python
python模块导入的细节详解
Dec 10 #Python
pandas每次多Sheet写入文件的方法
Dec 10 #Python
Python用61行代码实现图片像素化的示例代码
Dec 10 #Python
Python从数据库读取大量数据批量写入文件的方法
Dec 10 #Python
You might like
如何用phpmyadmin设置mysql数据库用户的权限
2012/01/09 PHP
浅析php中array_map和array_walk的使用对比
2016/11/20 PHP
关于PHP定时发送服务的解决办法
2017/04/23 PHP
Laravel5.5新特性之友好报错以及展示详解
2017/08/13 PHP
PHP获取二叉树镜像的方法
2018/01/17 PHP
js几个不错的函数 $$()
2006/10/09 Javascript
JS 的应用开发初探(mootools)
2009/12/19 Javascript
jQueryUI如何自定义组件实现代码
2010/11/14 Javascript
jquery实现点击文字可编辑并修改保存至数据库
2014/04/15 Javascript
jQuery实现table隔行换色和鼠标经过变色的两种方法
2014/06/15 Javascript
Javascript中this关键字的一些小知识
2015/03/15 Javascript
JavaScript组合模式学习要点
2016/08/26 Javascript
深入解读Node.js中的koa源码
2019/06/17 Javascript
Vue项目结合Vue-layer实现弹框式编辑功能(实例代码)
2020/03/11 Javascript
python数据结构之二叉树的遍历实例
2014/04/29 Python
Python和GO语言实现的消息摘要算法示例
2015/03/10 Python
在RedHat系Linux上部署Python的Celery框架的教程
2015/04/07 Python
Python输出PowerPoint(ppt)文件中全部文字信息的方法
2015/04/28 Python
python验证码识别的示例代码
2017/09/21 Python
Django中使用celery完成异步任务的示例代码
2018/01/23 Python
python读取csv和txt数据转换成向量的实例
2019/02/12 Python
Django框架下静态模板的继承操作示例
2019/11/08 Python
python实现图片,视频人脸识别(opencv版)
2020/11/18 Python
WoolOvers爱尔兰:羊绒、羊毛和棉针织品
2017/01/04 全球购物
中专自荐信
2013/10/13 职场文书
汽车检测与维修专业求职信
2013/10/30 职场文书
法律工作求职自荐信
2013/10/31 职场文书
广告学专业推荐信范文
2013/11/23 职场文书
小车司机岗位职责
2013/11/25 职场文书
成人继续教育实施方案
2014/03/01 职场文书
九一八事变纪念日演讲稿
2014/09/14 职场文书
店铺转让协议书
2015/01/29 职场文书
社区党支部公开承诺书
2015/04/29 职场文书
如何才能写好调研报告?
2019/07/03 职场文书
恶魔之树最顶端的三颗果实 震震果实上榜,第一可以制造岩浆
2022/03/18 日漫
5人制售《绝地求生》游戏外挂获利500多万元 被判刑
2022/03/31 其他游戏