title: How do I return an array from an array function using groovy?
body: <p>How do I return an array from an array function using Groovy? I am currently trying it with the following code but I am getting errors when I execute the code! I want to be able to get values from an array function where I am extracting the data from excel and I want to be able to use arbitrary values retrieved from the function. Can anyone help?</p>
  
  <p>Code:</p>
  
  <pre><code>package Check
  
  import org.apache.commons.io.FileUtils;
  import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  import org.apache.poi.xssf.usermodel.XSSFCell;
  import org.apache.poi.xssf.usermodel.XSSFRow;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  class Second {
  
      static main(args) {
          //def alpo = new String[2][3]
          def alpo = getTableArray("KSuite");
          println "£34." + alpo[1][2]
      }
  
      public static String[][] getTableArray(String xlSheet) throws Exception {
          FileInputStream input = new FileInputStream(new File("C:\\Temp\\KSuite.xlsx"));
          //System.out.println(input.path);
          XSSFWorkbook workbook = new XSSFWorkbook(input);
          //System.out.println(xlSheet);
          XSSFSheet sheet = workbook.getSheet(xlSheet); 
          int ci;//,cj;
          XSSFRow r = sheet.getRow(sheet.getFirstRowNum());
          int jMax=Math.max(r.getLastCellNum()-r.getFirstCellNum(),2);
          int iMax=sheet.getLastRowNum()-sheet.getFirstRowNum();
          def tabArray= new String[sheet.getLastRowNum()-sheet.getFirstRowNum()][jMax];
          //System.out.println(sheet.getLastRowNum()-sheet.getFirstRowNum());
          //System.out.println(jMax);
  
          for (int i = sheet.getFirstRowNum()+1; i &lt;= sheet.getLastRowNum(); i++) {
              ci = i - 1;
              r = sheet.getRow(i);
              for (int j = 0; j &lt; jMax; j++) {
                  XSSFCell c = r.getCell(j, r.CREATE_NULL_AS_BLANK);
                  if(c.getCellType() == 1) {
                      tabArray[ci][j]=c.getStringCellValue();
                  } else {
                      tabArray[ci][j]=((float)(c.getNumericCellValue()) + "");
                  }
              }
          }
          input.close();
          // return(tabArray);
          // return(cj);
  
          return(tabArray);
          // return(cj);
      }
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>   Caught: java.lang.ArrayIndexOutOfBoundsException: 2
     java.lang.ArrayIndexOutOfBoundsException: 2
  at Check.Second.main(Second.groovy:15)
  </code></pre>
  
  <p>Table KSuite in KSuite.xlsx:</p>
  
  <pre><code>Script  Run 
  Login,  Yes
  Workspaces  No
  Users,  Yes
  </code></pre>