读取EXCEL表格

首先是http://www.runoob.com/python/python-func-xrange.html这个文章讲述的xrange和range之间的区别。

但是python3中只有range,没有xrange了,python3进行了优化。

import xlrd

file = r'D:\CSV\readexcel.xlsx'

wb = xlrd.open_workbook(filename=file)
ws = wb.sheet_by_name('Sheet1')
dataset=[]
for r in range(ws.nrows):
    col=[]
    for c in range(ws.ncols):
        col.append(ws.cell(r,c).value)
    dataset.append(col)
for x in dataset:
    print(x)
发布了44 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_38060122/article/details/83065234