标签:ddc [] close create case pre test void pid
作为一名小测试,一直想写代码,哈哈哈
不为了转开发,就是觉得很有意思,这回正好要测接口(之前也有测接口,但是都是手动的,没想到要用代码来测,真是too young too native)
话不多说,开始!
首先添加maven依赖,使用的是jxl方式
1 <dependency> 2 <groupId>net.sourceforge.jexcelapi</groupId> 3 <artifactId>jxl</artifactId> 4 <version>2.6.10</version> 5 </dependency>
读取excel数据
(先写着,感觉不是很合适,以后改)
1 /** 2 * 读取Excel数据 3 * @throws BiffException 4 * @throws IOException 5 */ 6 public static void readExcel() throws BiffException, IOException{ 7 File xlsFile = new File("caseFile/testFile.xls"); 8 //获得工作簿对象 9 Workbook workbook = Workbook.getWorkbook(xlsFile); 10 //获得所有工作表 11 Sheet[] sheets = workbook.getSheets(); 12 //遍历工作表 13 if (sheets != null){ 14 for (Sheet sheet : sheets){ 15 //获得行数 16 int rows = sheet.getRows(); 17 //获得列数 18 int cols = sheet.getColumns(); 19 //读取数据 20 for (int row = 0; row < rows; row++){ 21 for(int col = 0; col < cols; col++){ 22 System.out.printf("%10s", sheet.getCell(col,row).getContents()); 23 } 24 System.out.println(); 25 } 26 } 27 workbook.close(); 28 } 29 }
写入excel
1 /** 2 * 写入excel 3 */ 4 public static void writeExcel() throws IOException,WriteException{ 5 File xlsFile = new File("caseFile/testFile01.xls"); 6 //创建一个工作簿 7 WritableWorkbook workbook = Workbook.createWorkbook(xlsFile); 8 //创建一个工作表 9 WritableSheet sheet = workbook.createSheet("sheet", 0); 10 for (int row = 0; row < 10 ;row++){ 11 for (int col = 0; col < 10; col++){ 12 //向工作表中添加数据 13 sheet.addCell(new Label(col, row, "data" + row + col)); 14 } 15 } 16 workbook.write(); 17 workbook.close(); 18 }
标签:ddc [] close create case pre test void pid
原文地址:https://www.cnblogs.com/wutantan/p/10223878.html