python实现对Excle表格的读写

python实现对Excle表格的读写[Python基础]

1、使用xlrd模块读取数据

# 将excel表格内容导入到tables列表中
def import_excel(tab):
    # 创建一个空列表,存储Excel的数据
    tables = []
    for rown in range(1, tab.nrows):
        array = {"设备名称": "", "框": "", "槽": "", "端口": "", "onuid": "", "认证密码": "", "load": "", "checkcode": ""}
        array["设备名称"] = tab.cell_value(rown, 0)
        array["框"] = tab.cell_value(rown, 1)
        array["槽"] = tab.cell_value(rown, 2)
        array["端口"] = tab.cell_value(rown, 3)
        array["onuid"] = tab.cell_value(rown, 4)
        array["认证密码"] = tab.cell_value(rown, 9)
        array["load"] = tab.cell_value(rown, 10)
        array["checkcode"] = tab.cell_value(rown, 11)
        tables.append(array)
    return tables
# 导入需要读取Excel表格的路径
data = xlrd.open_workbook(r"G:	est.xlsx")
table = data.sheets()[0]
for i in import_excel(table):
     print(i)
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » python实现对Excle表格的读写