python单循环读取表数据excel

参考:https://www.jianshu.com/p/19219542bf23

python读取excel

单循环读取表数据

import xlrd
class DoExcel():

    def do_excel(self):
        data = xlrd.open_workbook(r'E:\mycode\test_python\excel01.xlsx')
        sheet1 = data.sheet_by_name('Sheet1')
        list = []
        for i in range(0, sheet1.nrows):
            sub_data = {}
            sub_data['一'] = sheet1.cell(i, 0).value # i行第一列
            sub_data['二'] = sheet1.cell(i, 1).value # i行第二列
            list.append(sub_data)

        return list

if __name__ == '__main__':
    DoExcel().do_excel()

你可能感兴趣的:(python,python)