筛选指定id列对另一个sheet中的值进行修改

Excel中包含多个sheet,联系的是唯一的id

import openpyxl

wb=openpyxl.load_workbook(r'E:\\shenghe\\excels\\branch\\房间配置.xlsx')
sheet1=wb['比赛场']
max_row_1=sheet1.max_row
max_col_1=sheet1.max_column
id_ls=[]
'''
column  序列
1 id
2 场地名称
3 比赛时间
4 报名时间
5 比赛轮数
6 每局轮数
7 参赛人数
8 初始积分
9 参赛条件 报名费用
10 场地分类
11 被踢标准
12 服务费比例
13 底分
14 等待时间
15 等待时间上限
16 炸弹数量
17 奖励分配 好友赛启用
'''
for i in  range(9,max_row_1+1):
    num_1=int(sheet1.cell(row=i,column=7).value)
    if num_1>=30:
        id_ls.append(sheet1.cell(row=i,column=1).value)
        pass
    pass

sheet2=wb['匹配校验器']
max_row_2=sheet2.max_row
max_col_2=sheet2.max_column
for j in range(9,max_row_2+1):
    id_t=sheet2.cell(row=j,column=1).value
    if id_t in id_ls:
        print(id_t,str(j))
        sheet2.cell(row=j,column=7).value=str(2)
        pass
    else:
        pass
    pass
'''
切记保存!!! 否则不生效
'''
#wb.save(r'E:\\shenghe\\excels\\branch\\房间配置-2.xlsx')

 

posted @ 2020-05-15 16:13  余者皆可  阅读(275)  评论(0)    收藏  举报