有三个文档,文件A、文件B、文件C,A中有一组元素,我们要在文件B中找出包含文件A中元素的行,将文件写入C中。其中固定要找的元素在B中的F列,所以这里我们限定
if sheet1.cell(i + 1, 6).value in list_result:
整体代码如下:
# -*- coding:utf-8 -*-
__author__ = 'yangxin_ryan'
import openpyxl
"""
Solution
"""
class ExcelFunction(object):
def cell_handle(self, input_file1, input_file2, output_file):
# 读取查找元素
wb = openpyxl.load_workbook(input_file1, data_only=True)
sheet = wb.worksheets[0]
list_result = list()
col_len = sheet.max_column
row_len = sheet.max_row
for i in range(row_len):
for j in range(col_len):
list_result.append(sheet.cell(i + 1, j + 1).value)
# 读取查找集合
wb1 = openpyxl.load_workbook(input_file2, data_only=True)
sheet1 = wb1.worksheets[0]
l


