标签:odi .sh row open work lis name pen 数据
# -*- coding: gbk -*-
import xlrd
class Canshu:
def __init__(self,filepath):
"""
创建文件对象
:param filepath: 文件路径
"""
self.workbook = xlrd.open_workbook(filepath)
def get_canshu(self,sheetname,row,col):
"""
获取某一个单元格的数据
:param sheetname:
:param row: 行
:param col: 列
:return: 数据
"""
sheet = self.workbook.sheet_by_name(sheetname)
canshu = sheet.cell(row,col).value
return canshu
def get_cols(self,sheetname,col):
"""
获取一列单元格的数据
:param sheetname:
:param col: 第几列
:return: 第几列的数据,list
"""
sheet = self.workbook.sheet_by_name(sheetname)
cols = sheet.col_values(col)
return cols
def get_rows(self,sheetname,row):
"""
获取第几行的数据
:param sheetname:
:param row: 第几行
:return: 第几行的数据,list
"""
sheet = self.workbook.sheet_by_name(sheetname)
rows = sheet.row_values(row)
return rows
标签:odi .sh row open work lis name pen 数据
原文地址:https://www.cnblogs.com/sleep10000years/p/10599445.html