zoukankan      html  css  js  c++  java
  • python接口自动化--Excel

    1.操作步骤:


    (1)安装python官方Excel库-->xlrd

    (2)获取Excel文件位置并读取

    (3)读取sheet

    (4)读取指定rows和cols内容

    2.示例代码

    # -*- coding: utf-8 -*-
    import xlrd
    
    from datetime import date,datetime
    
    def read_excel():
        ExcelFile=xlrd.open_workbook(r'C:UsersAdministratorDocumentsautoTest	estexcel.xlsx')
    
    #获取目标EXCEL文件sheet名
        print (ExcelFile.sheet_names())
    
    #------------------------------------
    
    #若有多个sheet,则需要指定读取目标sheet例如读取sheet2
    
    #sheet2_name=ExcelFile.sheet_names()[1]
    
    #------------------------------------
    
    #获取sheet内容【1.根据sheet索引2.根据sheet名称】
    
    #sheet=ExcelFile.sheet_by_index(1)
    
        sheet=ExcelFile.sheet_by_name('Sheet1')
    
    #打印sheet的名称,行数,列数
    
        print("name===rows==cols")
        print(sheet.name,sheet.nrows,sheet.ncols)
    #获取整行或者整列的值
    
        rows=sheet.row_values(2)#第3行内容
    
        cols=sheet.col_values(1)#第二列内容
    
        print(cols,rows)
    
    #获取单元格内容
    
        print(sheet.cell(1,0).value.encode('utf-8'))
        print(sheet.row(1)[0].value.encode('utf-8'))
        print(sheet.row(1)[1].value.encode('utf-8'))
        print(sheet.row(6)[1].value.encode('utf-8'))
    
    
    if __name__ =="__main__":
        read_excel()
    ctype介绍 :
    
    0empty    1string     2number    3date    4boolean    5error
    
    操作方式
    
    sheet.row(6)[1].ctype(1)
    

      

  • 相关阅读:
    window下eclipse4.5+hadoop2.6.1开发环境配置
    sqoop1.4.6从mysql导入hdfshivehbase实例
    sqoop1.9.7安装和使用
    sqoop1.4.6导出oracle实例
    sqoop1.4.6配置安装
    java 操作hbase1.2
    hbase-1.2.5完全分布式部署
    hadoop2.6环境中部署hive1.2.2的错误
    hive 创建表和导入数据实例
    hive1.2.2部署
  • 原文地址:https://www.cnblogs.com/test_home_c/p/10186391.html
Copyright © 2011-2022 走看看