Python 处理 Excel 操作 (一)____ xlrd

读取操作


import xlrd

打开 Excel 文件

excel = xlrd.open_workbook('excel.xls')

查看 sheet 名

excel.sheet_names()

得到第一个工作表,或者通过索引顺序,或工作表名称

table = excel.sheets()[0]
table = excel.sheet_by_index(0)
table = excel.sheet_by_name(u'Sheet1')

获取行数和列数

nrows = table.nrows
ncols = table.ncols
获取整行和整列的值
table.row_values(i)
table.col_values(i)

循环行,得到索引的列表

for rownum in range(table.nrows):
    print table.row_values(rownum)
原文地址:https://www.cnblogs.com/S-yesir/p/4828811.html