title: How to Iteratethrough excel sheet using testNG dataprovider for multiple sets of data?
body: <p>I have been working with TestNg for a while but I have a new req that I cant seem to figure out. </p>
  
  <p>I have an excel file(sample.xls), sheet name=Dataset that has the following:</p>
  
  <p>testdata1  ex1   ex2    ex3 ex4</p>
  
  <pre><code>      1   2    3 4 testdata1
  </code></pre>
  
  <p>testdata2   ex1   ex2    ex3 ex4</p>
  
  <pre><code>      5   6    7  8  testdata2
  </code></pre>
  
  <p>my script is similar to this:</p>
  
  <pre><code>import com.thoughtworks.selenium.*;
  
  import org.junit.AfterClass;
  import org.openqa.selenium.server.SeleniumServer;
  import org.testng.annotations.*;
  
  import java.io.File;
  import jxl.*; 
  
  
  public class DataProviderExample extends SeleneseTestCase{
  
  
      @DataProvider(name = "DP1")
      public Object[][] createData1() throws Exception{
          Object[][] retObjArr=getTableArray("test\\Resources\\Data\\sample.xls",
                  "DataPool", "testdata1");
          return(retObjArr);
      }
  
      @Test (dataProvider = "DP1")
      public void testDataProviderExample(String ex1, 
              String ex2, String ex3, String ex4) throws Exception {    
         ///Extensive coding here but for simplicity I will just print 
              System.out.println(ex1);
              System.out.println(ex2);
              System.out.println(ex3);
              System.out.println(ex\4);
      }
  
      @AfterClass
      public void tearDown(){
          selenium.close();
          selenium.stop();
      } 
  
      public String[][] getTableArray(String xlFilePath, String sheetName, String tableName) throws Exception{
          String[][] tabArray=null;
  
              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();
  
              Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 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-1][endCol-startCol-1];
              ci=0;
  
              for (int i=startRow+1;i&lt;endRow;i++,ci++){
                  cj=0;
                  for (int j=startCol+1;j&lt;endCol;j++,cj++){
                      tabArray[ci][cj]=sheet.getCell(j,i).getContents();
                  }
              }
  
  
          return(tabArray);
      }
  
  
  }//end of class
  </code></pre>
  
  <p>My question is: How should I modify this script so that my Script goes through both sets of data from the excel sheet. Right now the script goes through the first set of data (cells within testdata1). I want to also go through testdata2. The result I am looking for is:</p>
  
  <p>1
  2
  3
  4</p>
  
  <p>5
  6
  7
  8</p>
  
  <p>Thanks</p>