小罗问我怎么从excel中读取数据,然后我百了一番,做下记录
以下代码来源于:http://www.cnblogs.com/lhj588/archive/2012/01/06/2314181.html
excel数据图(小罗说数据要给客户保密,我随手写了几行数据):
python读取excel文件代码:
#!/usr/bin/env python # -*- coding: utf-8 -*- # 读取excel数据 # 小罗的需求,取第二行以下的数据,然后取每行前13列的数据 import xlrd data = xlrd.open_workbook('test.xls') # 打开xls文件 table = data.sheets()[0] # 打开第一张表 nrows = table.nrows # 获取表的行数 for i in range(nrows): # 循环逐行打印 if i == 0: # 跳过第一行 continue print table.row_values(i)[:13] # 取前十三列
excel的写操作等后面用到的时候在做记录