Python自动化(三)使用xlrt读取Excel数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gavinsun/article/details/77983353

在”C:/data/python.xlsx“文件中的Sheet1中,有这样几行数据:

姓名 QQ
天佑 555555555
小白 666666666

如果使用Python中的xlrt该如何读取数据呢?参考如下:

#coding:utf-8
import xlrd
filename=u"C:/data/python.xlsx"
workbook = xlrd.open_workbook(filename)
sheet1 = workbook.sheet_by_name("Sheet1")
print "总共有{lines}".format(lines=sheet1.nrows)
print "总共有{cols}".format(cols=sheet1.ncols)
# 遍历,输出所有行的内容
for line in range(0, sheet1.nrows): 
    name, qq = sheet1.row_values(line)  # 获取某行的数据
    print name, qq

猜你喜欢

转载自blog.csdn.net/gavinsun/article/details/77983353