在python中讀取Excal文件,需要引用xlrd模塊,因此建的這個python文件名為xlrd.py
部分代碼如下:
import xlrd
import os
newpath = os.chdir(r'Excal文件所在路徑')
filename = ‘Excal文件名’
file = os.join(os.getcwd(),filename)
xl = xlrd.open_workbook(file) #打開文件
table1 = xl.sheet_by_name('某一sheet頁的名字') #獲取sheet頁內的匯總數據
print table1.cell_value(0,0) #獲取第0行第0列的值
執行程序報"AttributeError: module 'xlrd' has no attribute 'open_workbook'",把python文件名xlrd1.py改為xlrd.py解決此問題