這篇文章主要介紹怎樣基于python操作excel并獲取內(nèi)容,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
背景:從excel表中獲取請求url、請求數(shù)據(jù)、請求類型、預期結(jié)果
因此,需要學會如何使用python從excel獲取這些信息
#coding=utf-8 import xlrd #創(chuàng)建對象時,獲取對應(yīng)excel 表格 #讀取Excel行數(shù) #獲取單元格內(nèi)容 class OperationExcel: def __init__(self,file_name = None,sheet_id = 0): if file_name: self.file_name = file_name self.sheet_id = sheet_id else: self.file_name = '../data.xlsx' self.sheet_id = 0 self.data =self.get_data() def get_line(self): return self.data.nrows def get_cell_value(self,row,col): return self.data.cell_value(row,col) def get_data(self): data = xlrd.open_workbook(self.file_name) tables = data.sheets()[self.sheet_id] return tables if __name__ == '__main__': opers = OperationExcel() print opers.get_line() print opers.get_cell_value(1,0)
以上是“怎樣基于python操作excel并獲取內(nèi)容”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!