首页 > 代码库 > python-操作excel、csv数据文件

python-操作excel、csv数据文件

1、excel文件操作

技术分享

# -*- coding: utf-8 -*-import  xlrdworkbook = xlrd.open_workbook(D:\\workspace\\eclipse-python\\test\\myexcel.xls)sheetname=workbook.sheet_names()#抓取所有sheet页的名称print myexcel is ,sheetname[0],sheetname[1],sheetname[2]#定位到sheet1worksheet1=workbook.sheet_by_name(u【工作月报】)#遍历sheet1中所有行rownum_rows=worksheet1.nrowsprint u总行数=,num_rowsfor i in range(num_rows):    row=worksheet1.row_values(i)    print u获取的第,i,u行的数据是,row[0],row[1],row[2]#遍历sheet1中所有列colnum_cols=worksheet1.ncolsprint u总列数=,num_colsfor j in range(num_cols):    col=worksheet1.col_values(j)    print u获取的第,i,u列的数据是,col[0],col[1],col[2],col[3],col[4]#遍历sheet1中所有单元格cellfor rown in range(num_rows):    for coln in range(num_cols):        cell = worksheet1.cell_value(rown,coln)        print cell

技术分享

 

python-操作excel、csv数据文件