python3中使用xlrd操作excel介绍

1.首先要安装xlrd

cmd后运行pit install xlrd,安装好xlrd后会有成功提示,xlrd是读取excel

2.导入xlrd包

import xlrd

3.打开excel文档

table = xlrd.open_workbook("****.xlsx")

4.读取sheet页面数据

①根据下标读取

sheet1 = table.sheets()[0]
②根据sheet_by_index()读取

sheet2=table.sheet_by_index(0)

③根据sheet_by_name()读取

sheet3=table.sheet_by_name("Sheet1")

5.读取表的行数和列数

rows=sheet1.nrows

columns=sheet1.ncols

print(rows,columns)

6.读取指定行的值和指定列的值

rowvalue=sheet1.row_values(1)

colvalue=sheet1.col_values(0)

print(rowvalue,colvalue)

posted @ 2018-08-23 19:46  xinxin8109  阅读(5408)  评论(0编辑  收藏  举报