# -*- coding: utf-8 -*-
#import numpy as np
import xlrd
#读取excel数据
def read_excel():
#文件位置
path = r'C:/'
file = 'rank.xlsx'
# 打开文件
data = xlrd.open_workbook(path + '/' + file)
#获取目标EXCEL文件sheet名
#a = data.sheet_names()
#print(a)
#获取sheet内容【1.根据sheet索引2.根据sheet名称】
#sheet=ExcelFile.sheet_by_index(1)
sheet=data.sheet_by_name('Sheet1')
#打印sheet的名称,行数,列数
print(sheet.name,sheet.nrows,sheet.ncols)
#获取整行或者整列的值
for i in range(1,sheet.nrows):
rows = sheet.row_values(i) # 行内容
return rows
#设计矩阵
Python3读取excel
最新推荐文章于 2025-06-06 19:18:59 发布