# -*- coding: utf-8 -*-
import xlrd
from datetime import date,datetime
def read_excel():
#文件位置
ExcelFile=xlrd.open_workbook(r'C:\Users\wangxingyue1\Desktop\XinBangCount.xlsx')
#获取目标EXCEL文件sheet名
print (ExcelFile.sheet_names())
#------------------------------------
#若有多个sheet,则需要指定读取目标sheet例如读取sheet1
# sheet1_name=ExcelFile.sheet_names()[1]
#------------------------------------
#获取sheet内容【1.根据sheet索引2.根据sheet名称】
#sheet=ExcelFile.sheet_by_index(1)
sheet=ExcelFile.sheet_by_name('XinBangCount')
#打印sheet的名称,行数,列数
print(sheet.name,sheet.nrows,sheet.ncols)
#获取整行或者整列的值
rows=sheet.row_values(2)#第三行内容
cols=sheet.col_values(2)#第二列内容
cols.sort(reverse=True) # 降序,默认是升序
print(cols,rows)
if __name__ =='__main__':
read_excel()
python 导入 excel
最新推荐文章于 2025-06-08 12:44:58 发布