0
点赞
收藏
分享

微信扫一扫

python实用脚本(二)—— 使用xlrd读取excel

清冷的蓝天天 2022-04-07 阅读 144
python

本期主题:
python使用xlrd读取excel的脚本


往期链接:

  • python实用脚本(一)—— 批量修改目标文件夹下的文件名

# extract number of rows using Python
import xlrd

# Give the location of the file
loc = "sample.xls"
wb = xlrd.open_workbook(loc)

# return self._sheet_list[sheetx]
# 选择excel表中的哪一个sheet
sheet = wb.sheet_by_index(0)

# cell_value选择具体哪个元素,前为行,后为列 (row ,col)
print(sheet.cell_value(0, 0))
# Extracting number of rows
print(sheet.nrows)

# extract number of columns in Python
print(sheet.ncols)

# extracting all columns name in Python
for i in range(sheet.ncols):
    print(sheet.cell_value(0, i))

# extracting first column
sheet = wb.sheet_by_index(0)
for i in range(sheet.nrows):
    print(sheet.cell_value(i, 0))

# extract a particular row value
sheet = wb.sheet_by_index(0)
print(sheet.row_values(1))
举报

相关推荐

0 条评论