封装python读取excel内容,xlrd
# encoding = utf-8 import xlrd class ExcelOperation(object): '''封装excel内容读取方法''' def __init__(self,file_name="测试.xlsx",sheet_id=0): self.file_name = file_name self.sheet_id = sheet_id self.data = self.get_data() '''获取excel内容''' def get_data(self): workbook = xlrd.open_workbook(self.file_name) data = workbook.sheets()[self.sheet_id] return data '''获取总行数''' def get_nrows(self): return self.data.nrows '''获取总列数''' def get_ncols(self): return self.data.ncols '''获取单元格内容''' def get_cell_values(self,row,col): return self.data.cell_value(row,col) if __name__ == '__main__': operation = ExcelOperation() print(operation.get_ncols()) print(operation.get_nrows()) print(operation.get_cell_values(0,0))
posted on 2020-09-19 19:43 ClarenceSun 阅读(115) 评论(0) 编辑 收藏 举报