【PYTHON】操作excel笔记

import xlrd

book = xlrd.open_workbook('..//data//case1.xls')

# 获取excel对象
print(book.sheets())

# 获取excel表名
print(book.sheet_names())

# 几张表 
print(len(book.sheets()))

# 选择某一张表
table1 = book.sheets()[0]

# 通过索引获取表
table2 = book.sheet_by_index(0)

# 通过表名获取表
table3 = book.sheet_by_name('sheet1')

# 获取行数
nrows = table3.nrows
print(nrows)

# 获取列数
ncol = table3.ncols
print(ncol)

# 获取某一行值
row_values = table3.row_values(0)
print(row_values)

# 获取某一列的值
col_values = table3.col_values(0)
print(col_values)

# 获取单元格值
cell_value_1 = table1.row(5)[5].value
print(cell_value_1)

cell_value_2 = table1.col(1)[1].value
print(cell_value_2)

cell_value_3 = table2.cell(2,2).value
print(cell_value_3)

  

posted @ 2020-03-12 17:21  WANG-X  阅读(236)  评论(0编辑  收藏  举报