Python读取excel 数据

1、安装xlrd

2、官网

通过官网来查看如何使用python读取Excel,python excel官网: http://www.python-excel.org/

 

实例:

(1)Excel内容

 

                                                                                                                                     把我的小埋放上去嘿嘿

 (2)代码实现

# _*_ coding:utf-8 _*_

import xlrd

if __name__ == '__main__':

    # excel文件全路径
    xlPath = r"c:\Users\yhq\Desktop\test.xlsx"    #这里遇到一个问题 要把C改为c

    # 用于读取excel
    xlBook = xlrd.open_workbook(xlPath)

    # 获取excel工作簿数
    count = len(xlBook.sheets())

    print u"工作簿数为:  ", count

    # 获取 表 数据的行列数
    table = xlBook.sheets()[0]
    nrows = table.nrows
    ncols = table.ncols
    print u"表数据行列为(%d, %d)" % (nrows, ncols)

    # 循环读取数据
    for i in xrange(0, nrows):
        rowValues = table.row_values(i)  # 按行读取数据

        # 输出读取的数据
        for data in rowValues:
            print data, "    ",

        print ""

 

posted @ 2019-10-11 16:57  云深不知处!  阅读(1125)  评论(3编辑  收藏  举报