Python openpyxl 遍历所有sheet 查找特定字符串的方法
如下所示:
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
相关推荐
dayslrk 2020-08-16
rookieliang 2020-06-15
up0 2020-06-13
cas的无名 2020-06-09
LULUBAO 2020-05-03
真新镇的涅法雷姆 2020-04-29
星辰大海的路上 2020-03-02
sunny0 2020-03-02
HongKongPython 2020-01-29
zcabcd 2020-01-05
liugan 2019-12-29
jzlixiao 2019-10-28
A宇 2019-09-03
allentony 2019-09-06
socket 2019-09-02
秋草正离离 2019-04-16
zcabcd 2019-07-01
LittleCoder 2019-07-01