Python 读取Excel数据 xlrd

#导入相关模块
from xlrd import open_workbook

#打开excel
file = open_workbook("test.xlsx")

#获取sheet:1按名称获取;2通过索引顺序获取 3 通过索引顺序获取
sheet = file.sheet_by_name("sheetname")
sheet = file.sheet_by_index(0)
sheet = file.sheets()[0]

#获取行数和列数
nrows = sheet.nrows #int
ncols = sheet.ncols #int

#通过行号获取整行值;通过列号获取整列值,返回类型<class 'list'>["",""]
row0=sheet.row_values(0)
col0=sheet.col_values(0)

#通过循环,打印所有行的内容
for i in range(nrows):
    print(sheet.row_values(i))

#获取某个单元格的值,返回值是str
cell=sheet.row_values(i)[j]
cell=sheet.cell(i,j).value
原文地址:https://www.cnblogs.com/belle-ls/p/10318508.html