python中操作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.读取指定行的值和指定列的值

data=sheet1.cell_value(row,col)
 
原文地址:https://www.cnblogs.com/lixiaoting/p/11090620.html