Python learning notes (simple excel operations) and python learning notes
The goal is to design an interface automation testing framework.
Use Cases are written in excel and built using python's pyunit
The excel processing module has been installed.
This simple application
Create an excel file named “testcase.xls in advance"
The operation code is as follows:
1 #! /Usr/bin/env python 2 #-*-coding: utf_8-*-3 4 import xlrd 5 6 def read_testcase (): 7 workbook = xlrd. open_workbook (r 'e: \ work \ python case \ learn \ testcase.xls ') 8 # Open the excel file 9 print workbook according to the path. sheet_names () 10 # print all sheet names 11 table = workbook. sheet_by_name ('login') 12 # Get the corresponding sheet content through the sheet name 13 # You can also get the first sheet14 # table = workbook in order. sheets () [0] 15 print table. row_values (0) 16 print table. row_values (1) 17 print table. row_values (2) 18 print table. row_values (3) 19 # obtain the entire row of data (array) 20 print table by the number of rows. col_values (0) 21 print table. col_values (1) 22 print table. col_values (2) 23 # obtain column data (array) 24 print table by column number. cell (0, 0 ). value25 print table. cell (0, 1 ). value26 print table. cell (0, 2 ). value27 print table. cell (1, 0 ). value28 print table. cell (1, 1 ). value29 print table. cell (1, 2 ). value30 print table. cell (2, 0 ). value31 print table. cell (2, 1 ). value32 print table. cell (2, 2 ). value33 print table. cell (3, 0 ). value34 print table. cell (3, 1 ). value35 print table. cell (3, 2 ). value36 # retrieve data by Cell 37 38 if _ name _ = '_ main _': 39 read_testcase ()