robotium之读取excel

来源:互联网 发布:iphone7怎么关闭4g网络 编辑:程序博客网 时间:2024/05/21 00:45

现在测试用例都是在excel中,我先分享一个读取excel2003的代码:

package com.test;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.ArrayList;import java.util.List;import jxl.Cell;import jxl.Sheet;import jxl.Workbook;import jxl.read.biff.BiffException;public class text {public static void readExcel() throws BiffException, IOException{   //创建一个list 用来存储读取的内容    List list = new ArrayList();    Workbook rwb = null;    Cell cell = null;        //创建输入流    InputStream stream = new FileInputStream("d:\\测试用例.xls");        //获取Excel文件对象    rwb = Workbook.getWorkbook(stream);        //获取文件的指定工作表 默认的第一个    Sheet sheet = rwb.getSheet(0);         //行数(表头的目录不需要,从1开始)    for(int i=0; i<sheet.getRows(); i++){          //创建一个数组 用来存储每一列的值     String[] str = new String[sheet.getColumns()];          //列数     for(int j=0; j<sheet.getColumns(); j++){           //获取第i行,第j列的值      cell = sheet.getCell(j,i);             str[j] = cell.getContents();      System.out.println(sheet.getCell(0,0).getContents());                 }     //把刚获取的列存入list     list.add(str);    }    for(int i=0;i<list.size();i++){     String[] str = (String[])list.get(i);     for(int j=0;j<str.length;j++){      System.out.println(str[j]);     }    }  } public static void main(String args[]) { try {readExcel();} catch (BiffException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}            }}

 

 

这个方法要添加jxl.jar包;读取出来后就可以找到对应的行列;

晚上分享读取excel2010

0 0
原创粉丝点击