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 ""
