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_path10 self.execl = self.get_execl()11 12 def get_execl(self):13 tables = xlrd.open_workbook(self.execl_path)14 return tables15 16 def get_sheet(self):17 # 打开第一张表18 sheet_data = self.execl.sheets()[0]19 return sheet_data20 21 def get_lines(self):22 # 获取表的行数23 lines = self.get_sheet().nrows24 return lines25 26 def get_cell(self, row, cell):27 # 取第row行的第cell列内容28 data = self.get_sheet().cell(row, cell).value29 return data30 31 32 if __name__ == '__main__':33 book = OpenExecl()34 print(book.get_cell(0, 4))