脚本专栏 
首页 > 脚本专栏 > 浏览文章

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

(编辑:jimmy 日期: 2024/5/9 浏览:3 次 )

如下所示:

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 运用Django 开发后台接口的实例
下一篇:使用pandas实现csv/excel sheet互相转换的方法
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网