码迷,mamicode.com
首页 > 编程语言 > 详细

【python】Excel两表中姓名信息对比

时间:2020-05-24 20:58:46      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:read   coding   continue   姓名   code   column   object   filename   open   

Excel两表中姓名信息对比

Excel两表中姓名信息对比,及写入对比结果:

# -*- coding: UTF-8 -*-
from openpyxl import load_workbook
from openpyxl import Workbook

# 以‘xxx花名册.xlsx‘为准
yuanbook = load_workbook(filename=xxx花名册.xlsx,read_only=True)
objectbook = load_workbook(花名册0523.xlsx)

yuansheet = yuanbook[X]
objectsheet = objectbook[XXX]

for i in range(4,761):
    for j in range(4,761):
        cell_yuansheet = yuansheet.cell(row=i, column=3)
        cell_objectsheet = objectsheet.cell(row=j, column=3)
        yuancell_s = str(cell_yuansheet.value)
        objectcell_s = str(cell_objectsheet.value)
        print(正在处理,i,j)
        if objectcell_s == yuancell_s:
            result_cell = objectsheet.cell(row=i, column=18)
            result_cell.value = 存在
            print(f正好是{i}和{j})
            break
        else:
            continue
objectbook.save(花名册0523.xlsx)

 

【python】Excel两表中姓名信息对比

标签:read   coding   continue   姓名   code   column   object   filename   open   

原文地址:https://www.cnblogs.com/nfcf/p/12952379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!