ssp4599815
10/16/2017 - 9:40 AM

xlrd -- 读取Excel文件

使用python读取 Excel文件

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import xlrd

# 获取 Excel
workbook = xlrd.open_workbook('test.xls')
# 获取第一个sheet
sheet = workbook.sheet_by_index(0)
rows = sheet.nrows  # 行
cols = sheet.ncols  # 列 

for row in xrange(rows):
    # 获取第一行第一列
    ip = sheet.cell_value(row, 0)
    # 获取第一行第二列
    nfs = sheet.cell_value(row, 1)