zoukankan      html  css  js  c++  java
  • python 对Excel表格的读取

    import xlrd
    
    flbrd = "D:\考勤系统.xlsx"
    ws = xlrd.open_workbook(flbrd)
    # 获取所有sheet名字:ws.sheet_names()
    print('获取所有sheet名字',ws.sheet_names())
    # 获取sheet数量:ws.nsheets
    print('获取所有sheet对象',ws.nsheets)
    # 获取所有sheet对象:ws.sheets()
    print('获取所有sheet对象',ws.sheets())
    # 通过sheet名查找:ws.sheet_by_name("test”)
    print('通过sheet名查找',ws.sheet_by_name("Sheet1"))
    # 通过索引查找:ws.sheet_by_index(3)
    print('通过索引查找',ws.sheet_by_index(2))
    
    
    wp = ws.sheet_by_name("Sheet1")
    # 获取sheet名称
    print('获取sheet名称',wp.name)
    #获取sheet总行列数
    print('获取sheet总列数',wp.ncols)
    print('获取sheet总行数',wp.nrows)
    
    print('读取第一行的内容包括合并单元格',wp.row_values(0))
    print('获取单元格值类型和内容',wp.row(0))
    print('获取单元格是否存在数据',wp.row_types(0))
    
    print('读取第一行,地2-3列数据,不包含第四列数据',wp.row_values(0,1,3))
    print('读取第一列中的第三行到四行的数据',wp.col_values(0,2,5))
    print('获取单元格的类型和值',wp.row_slice(0,1,3))
    print('获取单元格类型',wp.row_types(1,0,2))
    
    print('获取单元格第一行第二列中内容',wp.cell_value(0,1))
    print('获取单元格第一行第二列中内容',wp.cell(0,1).value)
    print('获取单元格第一行第二列中内容',wp.row(0)[1].value)
    print('获取单元格第一行第二列中类型',wp.cell_type(0,1))
    print('获取单元格第一行第二列中类型',wp.cell(0,1).ctype)
    print('获取单元格第一行第二列中类型',wp.row(0)[1].ctype)
    
    print('转换成A1',xlrd.cellname(0,0))
    print('转换成$A$1',xlrd.cellnameabs(0,0))
    # print(' 把列由数字转换为字母表示',xlrd.colname(0,0))
    
    # 读取每个单元格的数据
    s = wp.ncols #
    b = wp.nrows #
    i = 0
    for i in range(b):
        for e in range(s):
           print(wp.cell_value(i, e))
  • 相关阅读:
    ActiveMQ 5.x 消息队列
    Spring Boot 整合 ElasticSearch 框架
    Spring Boot 整合 Logback 日志框架
    Spring Boot 整合定时任务和异步任务处理
    Spring 中使用 Java 5.0 Executor
    二级指针三种内存模型综合训练
    08-图8 How Long Does It Take (25 分)
    08-图9 关键活动 (30 分)
    08-图7 公路村村通 (30 分)
    C函数之index、strtoul
  • 原文地址:https://www.cnblogs.com/zhmiao/p/10530673.html
Copyright © 2011-2022 走看看