Python——读取excel行和

day1——读取excel行和列

今天是记录python学习的第一天,之前已经写过读取txt文件的代码了。
目前已安装的库有:
beautifulsoup4 4.6.3
bs4 0.0.1
cycler 0.10.0
jieba 0.39
kiwisolver 1.0.1
lxml 4.2.5
matplotlib 3.0.0
nltk 3.0.4
numpy 1.15.2
pip 18.1
pyparsing 2.2.2
python-dateutil 2.7.3

读取excel行和列

import xlrd

#读取excel文件
Excelfile=xlrd.open_workbook(r'filename.xls')

#获取读入文件的sheet
#索引从0开始
#也可以用名字的方式读取,但是一定要注意大小写
#sheet = Excelfile.sheet_by_name('Sheet1')
sheet = Excelfile.sheet_by_index(0)

#获取行内容,索引从0开始
rows=sheet.row_values(0)
print(rows)
#获取列内容,索引从0开始
cols=sheet.col_values(0)
print(cols)

print(sheet.name,sheet.nrows,sheet.ncols)

输出结果:
Python——读取excel行和_第1张图片

你可能感兴趣的:(python学习)