python 打开excel失败,求解!!!
xlrd版本:1.2.0
import xlrd
def open_excel():
try:
sport_score = xlrd.open_workbook(“excel/score.xlsx”)
except:
print(“打开excel失败!!!”)
try:
sheet = sport_score.sheet_by_index(0)
return sheet
except:
print(“打开score表失败!!!”)
sheet1 = open_excel()
if sheet1:
print(sheet1.nrows) # 打印 Sheet1 表的行数
else:
print(“无法打开score表”)
输出结果如下:
打开excel失败!!!
打开score表失败!!!
无法打开score表