读取配置表,循环输入对应数据

开发过程中遇到这样一个需求:
读取配置表,循环输入对应数据

即需要在上图中分别输入:姓名、证件号码、准考证号。再此之前,根据业务老师给的信息先做一个配置表,如下图所示:
读取配置表,循环输入对应数据

流程预览:读取配置表,循环输入对应数据

代码块:读取登录信息存入全局变量

详细代码

import openpyxl

def asone_user_config_load(config_filepath=r"D:\depthsdata\test\asone.xlsx"):
    workbook = openpyxl.load_workbook(config_filepath)
    worksheet = workbook["Sheet1"]
    
    result = []
    row_index = 1
    title_dict = {}
    for row in worksheet:
        #读取各标题行对应的坐标
        if row_index == 1:
            for col_index in range(len(row)):
                title_dict[col_index] = row[col_index].value
            row_index+=1
            continue
           
        #处理余下各行,结合标题坐标
        item_info = {}
        for col_index in range(len(row)):
            item_info[title_dict[col_index]] = row[col_index].value
        #将当前行的处理结果接入总结果集合
        result.append(item_info)
        
    return result

    
self.gv_asone_log_info = asone_user_config_load()

For 循环组件

读取配置表,循环输入对应数据

元素:self.gv_log_info
集合:self.gv_asone_log_info

输出组件

读取配置表,循环输入对应数据

功能:调试打印
结果:

Main.py- "StepNodeTag:102053500184",Note:读取登录信息存入全局变量
Main.py- "StepNodeTag:110925425454",Note:
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '漩涡鸣人', '证件号码': '321283199510103842', '准考证号': 2154121151}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '宇智波佐助', '证件号码': '321280199401084657', '准考证号': 5124542102}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '春野樱', '证件号码': '321210199507063546', '准考证号': 5456841575}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '犬冢牙', '证件号码': '321283199512110341', '准考证号': 6588451878}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '油女志乃', '证件号码': '321283199510235472', '准考证号': 8239812090}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '日向雏田', '证件号码': '3212801994510109862', '准考证号': 9603341255.4}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '奈良鹿丸', '证件号码': '3212101995070653474', '准考证号': 10966870420.8}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '秋道丁次', '证件号码': '3212831995127421224', '准考证号': 12330399586.2}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '山中井野', '证件号码': '321283199510103842', '准考证号': 13693928751.6}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '日向宁次', '证件号码': '321280199104245412', '准考证号': 15057457917}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '李洛克', '证件号码': '321210199214141752', '准考证号': 16420987082.4}
Main.py- "StepNodeTag:110927152179",Note:
{'姓名': '天天', '证件号码': '321283199211315721', '准考证号': 17784516247.8}

设置文本组件

读取配置表,循环输入对应数据

文本框内的内容依次为:self.gv_log_info[“姓名”]、self.gv_log_info[“证件号码”]、self.gv_log_info[“准考证号”]