python接口自动化学习之路(2)
学习xlrd,为接口自动化从excel读取case做准备
1.安装xlrd
进入Python\Python36-32\Scripts目录下面
输入pip install xlrd
2.pip安装成功后,如果pycharm引用包失败的情况,
请参考:https://blog.****.net/wujf90/article/details/79181886
3.学习xlrd
import xlrd #excel文件地址,引用时加r,不转义 excelfile=r'C:\注册.xlsx' #获取excel为对象 data=xlrd.open_workbook(excelfile) #打开excel文件 table=data.sheets()[0] #指定索引顺序获取工作表 table1=data.sheet_by_index(0) #通过索引顺序获取工作表 table2=data.sheet_by_name(u'case') #通过名字获取 print(table,table1,table2) #获取行数和列数 nrows=table.nrows ncols=table.ncols print(nrows,ncols) #获取整行或整列的值 table_rows_2=table.row_values(1)#获取第二行的数据 table_cols_2=table.col_values(1)#获取第二列的数据 print(table_rows_2) print(table_cols_2) #获取单元格数据 table_A1=table.cell_value(0,0)#取A1,取第一行第一列单元格 table_C2=table.cell_value(1,2) print(table_A1) print(table_C2) #使用行列索引来获取单元格数据 table_B3=table.row(2)[1].value #取第三行第二个单元格,即B3 table_C3=table.row(2)[2].value print(table_B3) print(table_C3) #先获取某一行,再取某一行的某个数据 table_B2=table_rows_2[1] table_C2=table_rows_2[2] print(table_B2) print(table_C2) #先获取某一列,再取某一列的某个数据 table_B5=table_cols_2[4] print(table_B5)