本期主题:
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))