Python xlrd获取表格信息

1. 安装

pip install xlrd

2. 使用

import xlrd

xlsx = xlrd.open_workbook('example.xlsx')

# 通过sheet名查找:xlsx.sheet_by_name("sheet1")
# 通过索引查找:xlsx.sheet_by_index(3)
table = xlsx.sheet_by_index(0)

# 获取单个表格值 (0,0)表示第一个值
value = table.cell_value(0, 0)
print(value )

# 获取表格行数
nrows = table.nrows

# 获取第2列所有值
name_list = [str(table.cell_value(i, 1)) for i in range(1, nrows)]
print(name_list)

猜你喜欢

转载自blog.csdn.net/u014779536/article/details/105053967
今日推荐