python 读取excel文件的小工具

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jiaoyangdetian/article/details/82660724
import numpy as np
import xlrd

class XSLToolBox(object):

    def __init__(self, path, name):

        self.path = path
        self.name = name

        return

    def LoadData(self, sheetIndex, nameslist):

        data = xlrd.open_workbook(self.path + self.name)
        table1 = data.sheets()[sheetIndex]  # 获取表中所有的有效的行数

        booksheet1 = data.sheet_by_index(0)  # 按索引获取某一行的数据,可用于获取一张表的表头
        cell1 = booksheet1.row_values(0)
        print('表头=', cell1)

        re_data = list([])
        for name in nameslist:
            value_one = np.array(table1.col_values(cell1.index(name)))
            re_data.append(value_one)

        return re_data

猜你喜欢

转载自blog.csdn.net/jiaoyangdetian/article/details/82660724