python操作excel

import xlrd

def read_excel():

    wb = xlrd.open_workbook(filename=file)#打开文件
    print(wb.sheet_names())#获取所有表格名字

    sheet1 = wb.sheet_by_index(0)#通过索引获取表格
    sheet2 = wb.sheet_by_name('年级')#通过名字获取表格
    print(sheet1,sheet2)
    print(sheet1.name,sheet1.nrows,sheet1.ncols)

    rows = sheet1.row_values(2)#获取行内容
    cols = sheet1.col_values(3)#获取列内容
    print(rows)
    print(cols)

    print(sheet1.cell(1,0).value)#获取表格里的内容,三种方式
    print(sheet1.cell_value(1,0))
    print(sheet1.row(1)[0].value)

  python操作excel表格

posted @ 2019-04-08 20:39  点滴努力-响应激情  阅读(84)  评论(0)    收藏  举报