package com.bestpay.bpbp.bill.init; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; import java.io.File; import java.io.IOException; public class ReadExcelDataForTestNG { private static String parementFile = "E:/test-xiaozhangException.xls"; private File file; public static String getParementFile() { return parementFile; } public static String getParementFileNext() { return parementFile; } public ReadExcelDataForTestNG(File file){ this.file = file; } public String[][] str(int sNO) { String[][] str = null; try { Workbook book = Workbook.getWorkbook(file); // 获得第一个工作表对象 Sheet sheet = book.getSheet(sNO); // 得到第一列第一行的单元格 int col = sheet.getColumns();// 得到列数 int row = sheet.getRows();// 得到行数 str = new String[row-1][col]; for (int i = 0; i < row-1; i++)// 循环进行读写 { for (int j = 0; j < col; j++) { Cell c = sheet.getCell(j, i+1); str[i][j]= c.getContents(); } } book.close(); } catch (BiffException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return str; } }
原文地址:http://7883830.blog.51cto.com/7873830/1727060