xlrd读取excel
import xlrd
import xlwt
import re
class ParseExcel(object):
def __init__(self, path, index):
self.path = path
self.index = index
def get_excel(self):
worksheet = xlrd.open_workbook(self.path)
return worksheet
def get_sheet_by_index(self):
return self.get_excel().sheet_by_index(self.index)
def get_sheet_rows(self, rows):
return self.get_sheet_by_index().row_values(rows)
def get_sheet_cols(self, cols):
return self.get_sheet_by_index().col_values(cols)
def get_all_row_col_max_nums(self):
"""
获取excle最大行和列,返回数字
"""
rows = self.find_sheet_by_name().nrows
cols = self.find_sheet_by_name().ncols
return rows, cols
def replace_str(self, reglar, newstr, oldstr):
return re.sub(reglar, newstr, oldstr)