接口自动化之 exce xlrdl基本操作

Posted lexus168

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了接口自动化之 exce xlrdl基本操作相关的知识,希望对你有一定的参考价值。

import xlrd


def read_excel():
    #打开文件
    sheet = xlrd.open_workbook(r"D:jiekoudataconfigcase1.xls")
    #获取所有sheet
    print(sheet.sheet_names())
    sheet2_name = sheet.sheet_names()[1]

    #根据索引或者名称获取sheet内容
    sheet2 = sheet.sheet_by_name("sheet1")
    sheet2 = sheet.sheet_by_index(0)
    print("====================>>>>>>>>>>>>>")
    #sheet 的名称,行数,列数
    print(sheet2.name,sheet2.nrows,sheet2.ncols)
    print("====================>>>>>>>>>>>>>")
    #获取整行整列的值
    rows = sheet2.row_values(3)
    cols = sheet2.col_values(2)
    print(rows)
    print(cols)
    print("====================>>>>>>>>>>>>>")
    #获取单元格内容
    print(sheet2.cell(2,3).value)
    print(sheet2.cell_value(2,3))
    print(sheet2.row(2)[3].value)
    print("====================>>>>>>>>>>>>>")
    #获取单元格内容数据类型
    print(sheet2.cell(2,3).ctype)
if __name__ == __main__:
    read_excel()


#python读取excel中单元格的内容返回的有5种类型,即上面例子中的ctype:1
# ctype : 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error

 

以上是关于接口自动化之 exce xlrdl基本操作的主要内容,如果未能解决你的问题,请参考以下文章

接口自动化--操作Excel获取需要数据

系统自动化~02 Python操作EXC表格(入门)

接口自动化测试Python_使用python对excel进行操作

Jquery基础之DOM操作

Python接口自动化之logging日志

Python接口自动化之pymysql数据库操作