当前位置: 首页 > 图灵资讯 > 行业资讯> python怎么把xls文件导入?

python怎么把xls文件导入?

发布时间:2026-03-11 22:05:04

python导入xls文件的方法:

1、导入模块

importxlrd

2、打开xls文件读取数据

data=xlrd.open_workbook('excel.xls')

3、获取工作表

table=data.sheets()[0]#通过索引顺序获得
table=data.sheet_by_index(0)#通过索引顺序获得
table=data.sheet_by_name(u'Sheeet1')#通过名字获取

4、获得整行和整列的值(返回数组)

table.row_values(i)
table.col_values(i)

5、获取行数和列数

table.nrows
table.ncols

6、获取单元格

table.cell(0,0).value
table.cell(2,3).value

请关注Python自学网了解更多Python知识。

相关文章

python中%d是什么

python中%d是什么

2026-03-13
Python使用什么划分语句块?

Python使用什么划分语句块?

2026-03-13
python如何取列表中的数据?

python如何取列表中的数据?

2026-03-13
怎么查看python.exe文件在哪?

怎么查看python.exe文件在哪?

2026-03-13
python2输出乱码怎么解决

python2输出乱码怎么解决

2026-03-13
如何用Python画一颗小树?

如何用Python画一颗小树?

2026-03-13