#!/bin/env python
# -*- coding : utf-8 -*-

import xlrd

#也可以以后尝试直接继承xlrd类
class excel(object):
    """a class for excel processing"""
    #初始化，并解析Excel，生成对象
    def __init__(self, filename):
        super().__init__()
        self.filename = filename + '.xls'      
        self.data = xlrd.open_workbook(self.filename)
        self.table = self.data.sheets()[0]
        self.checkflag = self.table.row_values(0)[0]  #标志位
        self.row_cnt = self.table.nrows #所有行数，包括标题和列表行
        # if self.checkflag == "巡检":
        #     print("yes")
    #按行读取
    def show_row(self,row_num):
        print(self.table.row_values(row_num))
        return(self.table.row_values(row_num))
    #按列读取
    def show_col(self,col_num):
        print(self.table.col_values(col_num))
    #读取所有的记录，返回列表，下一步存入数据库
    def read_all_record(self):
        record = [  self.table.row_values(i) for i in range(2,self.row_cnt) ] #前两行不存入
        return record


# if __name__ == '__main__':
#     a = excel('2')
#     if a.checkflag == "巡检":
#         a.show_row(0)
#         a.show_col(3)

