Python 讀取Excel檔案

來源:互聯網
上載者:User

標籤:一個   執行   class   cell   check   工作   body   case   xls   

#! usr/bin/env pythonimport xlrdimport timeclass readExcel:    def __init__(self,excel_file):        self.excel_file = excel_file        self.http_method = ‘‘        self.request_url = ‘‘        self.request_param = ‘‘    def read_excel(self):        excel_data = []        #開啟Excel檔案        data = xlrd.open_workbook(self.excel_file)        #選擇一個工作表進行讀取        table = data.sheet_by_index(0)        for i in range(1,table.nrows):            excel_data.clear()            if table.cell(i,7).value.replace(‘\n‘,‘‘).replace(‘\r‘,‘‘) != ‘Yes‘:                continue            #讀取工作表中每一行的資料(table.row_value()返回的是列表形式)            #row_data = table.row_values(i)            self.case_id = str(int(table.cell(i, 0).value)).replace(‘\n‘,‘‘).replace(‘\r‘,‘‘)            self.test_desc = table.cell(i, 1).value.replace(‘\n‘,‘‘).replace(‘\r‘,‘‘)            self.request_url = table.cell(i, 3).value.replace(‘\n‘,‘‘).replace(‘\r‘,‘‘)            self.test_method = table.cell(i, 4).value.replace(‘\n‘,‘‘).replace(‘\r‘,‘‘)            self.request_param = table.cell(i, 5).value.replace(‘\n‘,‘‘).replace(‘\r‘,‘‘)            self.check_point = table.cell(i, 6).value.replace(‘\n‘,‘‘).replace(‘\r‘,‘‘)            self.active = table.cell(i, 7).value.replace(‘\n‘,‘‘).replace(‘\r‘,‘‘)            excel_data.append((self.case_id,self.test_desc,self.request_url,self.test_method,self.request_param,self.check_point,self.active))            yield excel_data            print(‘我執行了一次‘)if __name__ == ‘__main__‘:    file = readExcel(‘TestCase.xlsx‘)    for i in file.read_excel():        print(i)

 

Python 讀取Excel檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.