python讀取excel中的內容

2022-06-23 10:33:16 字數 678 閱讀 8509

pip install xlrd==1.2.0
import xlrd

步驟二:

讀取excel內容

data = xlrd.open_workbook(r'

c:\users\administrator\desktop\test.xlsx

') # xlrd 1

.0版本才支援xlsx檔案,先版本支援的是xls

# table = data.sheets()[0

]# 根據sheet索引或者名稱獲取sheer內容

sheet0 = data.sheet_by_name('

sheet1')

# rows = sheet0.row_values(3

) # 根據行獲取內容

# print(rows)

# 獲取某一列的內容

# cols = sheet0.col_values(3

)# print(cols)

allcount =sheet0.nrows # 獲取總行數

# a = sheet0.cell_value(1, 0).encode('

utf-8')

# print(a)

# a = sheet0.row(1)[4].value #獲取某一行某列的內容

python從excel中讀取資料

參考文獻 讀取excel 資料需要用到xlrd或者openpyxl模組,所以先安裝xlrd openpyxl 直接pip install xird openpyxl xlrd和openpyxl區別 1.xlrd能處理的最大行數為65535,超過這個行數的檔案就需要用到openpyxl,openpyx...

python從Excel中讀取資料

常用語法 file xlrd.open workbook 檔案路徑 開啟excel檔案 sheet info.sheet by name 工作表名稱 根據表名獲取工作表 rows num sheet.nrows 獲取表的行數 cols num sheet.ncols 獲取表的列數 rows shee...

python讀取excel的內容

這次看到別人用別的語言抓取excel中的內容,自己也試了一下,昨晚確實遇到了不少問題,首先就是很糟糕,讓人很奔潰的編碼問題,這也是python中的乙個難點吧,目前有很多的編碼方式,gbk,utf 8,gb2322,在python中提到unicode,一般指的是unicode物件,例如 哈哈 的uni...