import xlrd def read_excel(): #打开文件 sheet = xlrd.open_workbook(r"D:jiekoudataconfigcase1.xls") #获取所有sheet print(sheet.sheet_names()) sheet2_name = sheet.sheet_names()[1] #根据索引或者名称获取sheet内容 sheet2 = sheet.sheet_by_name("sheet1") sheet2 = sheet.sheet_by_index(0) print("====================>>>>>>>>>>>>>") #sheet 的名称,行数,列数 print(sheet2.name,sheet2.nrows,sheet2.ncols) print("====================>>>>>>>>>>>>>") #获取整行整列的值 rows = sheet2.row_values(3) cols = sheet2.col_values(2) print(rows) print(cols) print("====================>>>>>>>>>>>>>") #获取单元格内容 print(sheet2.cell(2,3).value) print(sheet2.cell_value(2,3)) print(sheet2.row(2)[3].value) print("====================>>>>>>>>>>>>>") #获取单元格内容数据类型 print(sheet2.cell(2,3).ctype) if __name__ == '__main__': read_excel() #python读取excel中单元格的内容返回的有5种类型,即上面例子中的ctype:1 # ctype : 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error