Python 读取excel
来源:互联网 发布:简单编程代码 编辑:程序博客网 时间:2024/04/30 21:29
#! encoding=utf-8import xlrd,xlwtimport xml.dom.minidomimport os,sysclass OpExcel(): table = '' tabledata = [] def __init__(self,path,sheet): try: data = xlrd.open_workbook(path) except Exception, e: print str(e) sys.exit() self.table = data.sheets()[sheet] def readexcel(self,nrows=0,ncols=0,colnameindex=0): if (nrows == 0) and (ncols == 0): # 没有定义要读取的行数和列数就取excel中的行数和列数 nrows = self.table.nrows ncols = self.table.ncols # print self.table.nrows colnames = self.table.row_values(colnameindex) for row in range(1,nrows): rowdata = self.table.row_values(row) if rowdata: tmp = {} for i in range(0,len(colnames)): tmp[colnames[i]] = rowdata[i] self.tabledata.append(tmp) return self.tabledata def readexcel2(self,nrows=0,ncols=0): if (nrows == 0) and (ncols == 0): # 没有定义要读取的行数和列数就取excel中的行数和列数 nrows = self.table.nrows ncols = self.table.ncols for row in range(1,nrows): tmp = [] for col in range(0,ncols): tmp.append(self.table.cell(row,col).value) self.tabledata.append(tmp) return self.tabledata # def writeexcel(self,nrow,ncol,data): # self.table.cell(nrow,ncol).value = dataif __name__ == "__main__": path = r'D:\Python\excel\2\23.xlsx' e = OpExcel(path,0) data = e.readexcel() print data
0 0
- python读取excel
- python 读取excel --zhaokuo719
- python 读取excel
- python读取EXCEL
- python读取excel
- python 读取Excel
- Python excel文件读取
- 用python读取excel
- Python 读取excel
- python读取excel文件
- python读取excel文件
- python 读取不规则excel
- python读取excel数据
- python读取excel数据
- python 读取excel数据
- python读取excel文件
- python读取excel数据
- python读取Excel
- Oracle 索引 详解
- 作业2
- 如何采集企业信息公示系统
- IT忍者神龟之Beetl 模版引擎Hello版本
- 雅思考试经验分享,G类移民不可错过!
- Python 读取excel
- 从数组中找出所有组合为s的数
- 对于锚点和position的理解
- deb package in Linux..
- CString类的完美总结
- 加载数据提示动画
- ////终于写完作业了////
- HashMap,LinkedMap,TreeMap的区别
- LeetCode 问题汇总(算法,难度,频率)