前言
xlsx写方法参考此连接:http://www.cnblogs.com/whf191/p/5482485.html
xlrd是用来读的,使用前需安装 pip install xlrd
例子
fname = 's1.xlsx'bk = xlrd.open_workbook(fname)#获取sheet总数shxrange = range(bk.nsheets)try: #操作第一个工作薄 sh = bk.sheet_by_name("Sheet1")except Exception,e: print e#获取行数nrows = sh.nrows#获取列数ncols = sh.ncolsprint u"行数:%s,列数:%s" % (nrows,ncols)#获取某一列数据cell_value = sh.cell_value(1,1)print cell_value#获取所有行数据row_list = []for i in range(1,nrows): row_data = sh.row_values(i) row_list.append(row_data)for i in row_list: for i2 in i: print i2