python讀取execl資料檔案

來源:互聯網
上載者:User

標籤:lis   gdi   __name__   從表   turn   表頭   work   ber   介面   

import xlrd
#將excel中資料轉換為列表
def excel_to_list(file,tag):
data_list=[]
#解析檔案
book=xlrd.open_workbook(file)
# print(type(book))
#擷取到自己想要的標籤頁
tag=book.sheet_by_name(tag)
#擷取tag頁行數
row_num=tag.nrows
#擷取tag頁列數
# cols_num=tag.ncols
# print(row_num,cols_num)
#擷取表頭,及第一行行資料
header=tag.row_values(0)
#print(header)
#從表頭下一行開始讀
for i in range(1,row_num):
#讀書沒一行資料
row_data=tag.row_values(i)
#等長兩列錶轉為字典,zip函數等長處理, 表頭為key,用例中資料為value。
d=dict(zip(header,row_data))
# print(d)
data_list.append(d)
return data_list

#在資料列表中根據測試案例名稱擷取對應的用例字典
def get_test_data(test_name,test_list):
for test_dic in test_list:
if test_name==test_dic["test_name"]:
return test_dic
if __name__ == ‘__main__‘:
file="介面測試案例.xls"
tag=‘BingdingCard‘
test_name="test_no_exist_cardnumber_bound"
test_list=excel_to_list(file,tag)
print(get_test_data(test_name,test_list))

python讀取execl資料檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.