码迷,mamicode.com
首页 > 编程语言 > 详细

python操作excel

时间:2019-04-08 21:30:38      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:read   sheet   cell   class   通过   内容   三种方式   xlrd   file   

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表格

python操作excel

标签:read   sheet   cell   class   通过   内容   三种方式   xlrd   file   

原文地址:https://www.cnblogs.com/testdog-007/p/10673228.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!