excle转list

import xlrd
def read_exlce(excelFile,index=0):
    read=xlrd.open_workbook(filename=excelFile)
    sheet=read.sheets() #读取所有sheet表
    curSheet=sheet[index]#读取指定的sheet表

    return curSheet

def exlce_to_list(curSheet):#一个sheet转为一个二维数组
    rows=curSheet.nrows
    cols=curSheet.ncols
    list=[]
    for row in range(rows):
        list2=[]
        for col in range(cols):
            list2.append(curSheet.cell(row,col))
        list.append(list2)
    return list

if __name__=='__main__':
    sheet=read_exlce("D:\jodie\jodiepy\data_drive\date.xlsx")
    list=exlce_to_list(sheet)
    print(list)

 

posted @ 2020-02-16 16:07  wakey  阅读(195)  评论(0编辑  收藏  举报