#导入相关模块from xlrd import open_workbook#打开excelfile = 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 #intncols = sheet.ncols #int#通过行号获取整行值;通过列号获取整列值,返回类型["",""]row0=sheet.row_values(0)col0=sheet.col_values(0)#通过循环,打印所有行的内容for i in range(nrows): print(sheet.row_values(i))#获取某个单元格的值,返回值是strcell=sheet.row_values(i)[j]cell=sheet.cell(i,j).value