1 import xlrd 2 3 4 class OpenExecl: 5 def __init__(self, file_path=None): 6 if file_path == None: 7 self.execl_path = r"H:***.xls" 8 else: 9 self.execl_path = file_path 10 self.execl = self.get_execl() 11 12 def get_execl(self): 13 tables = xlrd.open_workbook(self.execl_path) 14 return tables 15 16 def get_sheet(self): 17 # 打开第一张表 18 sheet_data = self.execl.sheets()[0] 19 return sheet_data 20 21 def get_lines(self): 22 # 获取表的行数 23 lines = self.get_sheet().nrows 24 return lines 25 26 def get_cell(self, row, cell): 27 # 取第row行的第cell列内容 28 data = self.get_sheet().cell(row, cell).value 29 return data 30 31 32 if __name__ == '__main__': 33 book = OpenExecl() 34 print(book.get_cell(0, 4))