Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import jxl.Cell;
- import jxl.Sheet;
- import jxl.Workbook;
- public class DataproviderMgr{
- private String xlFilePath;
- private String sheetName;
- private String tableName;
- public void setDataprovider(String xlFilePath, String sheetName, String tableName) {
- try {
- this.xlFilePath = xlFilePath;
- } catch (Exception e) {
- System.out.println("[ERROR] [DataProviderMgr] [setDataprovider]: " + e);
- }
- this.sheetName = sheetName;
- this.tableName = tableName;
- }
- // get all rows for table
- public String[][] getData() throws Exception {
- String[][] retObjArr = getTableArray(this.xlFilePath,this.sheetName,this.tableName);
- return(retObjArr);
- }
- //Reads in the data values from an XLS spreadsheet. NOTE excel 2007 not supported.
- private String[][] getTableArray(String xlFilePath, String sheetName, String tableName){
- String[][] tabArray=null;
- try{
- Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
- Sheet sheet = workbook.getSheet(sheetName);
- int startRow,startCol, endRow, endCol,ci,cj;
- Cell tableStart=sheet.findCell(tableName);
- startRow=tableStart.getRow();
- startCol=tableStart.getColumn();
- // startRow calculations are made to include the headers row
- Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow, 100, 64000, false);
- endRow=tableEnd.getRow();
- endCol=tableEnd.getColumn();
- //System.out.println("startRow="+startRow+", endRow="+endRow+", " + "startCol="+startCol+", endCol="+endCol);
- tabArray=new String[endRow-startRow][endCol-startCol-1];
- ci=0;
- for (int i=startRow;i<endRow;i++,ci++){
- cj=0;
- for (int j=startCol+1;j<endCol;j++,cj++){
- tabArray[ci][cj]=sheet.getCell(j,i).getContents();
- }
- }
- }
- catch (Exception e) {
- System.out.println("[ERROR] [DataProviderMgr] [getTableArray]: " + e);
- }
- return(tabArray);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement