日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python28 excel读取模块xlrd

發(fā)布時(shí)間:2024/7/5 python 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python28 excel读取模块xlrd 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

安裝:

pip install xlrd

?

簡(jiǎn)單使用:

import xlrdbook = xlrd.open_workbook(r'C:\Users\dinghanhua\Desktop\yqqapi.xlsx') # 打開(kāi)excel print("the number of sheets:",book.nsheets) # sheet數(shù)量 print("sheet_names:",book.sheet_names()) # sheetname列表 sheet1 = book.sheet_by_index(0) # 通過(guò)索引取sheet print(sheet1.name,sheet1.nrows,sheet1.ncols) #sheet名稱(chēng)、行數(shù)、列數(shù) print(sheet1.cell(0,0).value) #cell值 print(sheet1.cell_value(0,1)) #cell值 sheet2 = book.sheet_by_name("sheet2") # 通過(guò)sheetname取sheet print(sheet2.name,sheet2.nrows,sheet2.ncols)# 獲取sheet所有的數(shù)據(jù) for row in range(sheet1.nrows):for col in range(sheet1.ncols):print(sheet1.cell_value(row,col),end='\t')print('\n')print(sheet1.col_values(0,1,sheet1.nrows)) # 獲取第一列,第2行的所有值print(sheet1.row(1)) # 獲取第二行的值for col in range(sheet1.ncols): # 按列獲取值,每列是listprint(sheet1.col_values(col,0,sheet1.nrows))for row in range(sheet1.nrows): # 按行獲取值;每行都是listprint(sheet1.row_values(row,0,sheet1.ncols))

?

有的單元格帶有左右空格,取值時(shí)用strip()處理下

cell = str(sheet1.cell_value(0,0)).strip()

?

?

the end!

?

轉(zhuǎn)載于:https://www.cnblogs.com/dinghanhua/p/10348076.html

總結(jié)

以上是生活随笔為你收集整理的python28 excel读取模块xlrd的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。