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; } }