#coding=utf-8
import xlrd
class excel_read:
def __init__(self, excel_path=r'D:\\python_demoset\\util\\case.xls',encoding='utf-8',index=0):
self.data=xlrd.open_workbook(excel_path) ##获取文本对象
self.table=self.data.sheets()[index] ###根据index获取某个sheet
self.rows=self.table.nrows ##3获取当前sheet页面的总行数,把每一行数据作为list放到 list
def get_data(self):
result=[]
for i in range(self.rows):
col=self.table.row_values(i) ##获取每一列数据
print(col)
result.append(col)
print(result)
return result
if __name__ == '__main__':
excel_read().get_data()
##获取的结果样式[[],[],[],[]]
python 简单读取 excel 数据并存储为list
最新推荐文章于 2024-05-13 05:21:52 发布