xlrd模块支持读取xlsx和xls两种格式的excel表格数据,使用之前需要先安装(可以通过pip安装)
import xlrd
#读取excel文件路径
readfile = xlrd.work_bork(r'excel文件所在路径')
#获取sheet
sheet = readfile.sheet_names()
obj_sheet = readfile.sheet_by_name('sheet1')
#获取行数和列数
row = obj_sheet.nrows
col = obj_sheet.ncols
#获取行和列的数据
for i in range (row):
print(obj_sheet.row_values(i))
for j in range (col):
print(obj_sheet.col_values(j))
#获取单元格数据
for i in range (row):
for j in range(col):
print (obj_sheet.cell_value(i,j))
标签:sheet,python,excel,obj,xlrd,col,row From: https://www.cnblogs.com/lhj818/p/17525546.html