xlrd读取excel

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):  # 打开excel
        worksheet = xlrd.open_workbook(self.path)
        return worksheet

    def get_sheet_by_index(self):  # 根据索引获取sheet
        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)








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值