xlrd是第三方库,需要安装。
可以用pip install xlrd安装,如果这样安装报错,那就下载源代码,用python setup.py install安装。
#coding:utf-8
"""黄哥Python远程视频培训班 黄哥所写
https://github.com/pythonpeixun/article/blob/master/python_shiping.md
咨询:qq:1465376564
"""
import xlrd
def print_xls(path):
data = xlrd.open_workbook(path)
table = data.sheets()[0]
nrows = table.nrows
books = []
for i in range(nrows):
ss = table.row_values(i)
if "Book" in ss:
books.append(ss)
sum = 0
for i,item in enumerate(books):
print int(i+1),item[0],item[1],int(item[2]),int(item[3])
sum +=item[3]
print "total amount is:",int(sum)
<