How to read single D-array of data from excel in java using apache poi – in testNG

I have tried to read 2d array of data from excel using Apache POI in Java. It worked well. but am struggling to read single array of data from excel. because in TestNG data provider method, we cannot return the single dimension array just because of the syntax of data provider is 2d. so please advise me if you have idea to convert single dimension array. below is my code of reading 2d array from excel in TestNG framework with the help of Apache POI

@DataProvider
        public Object[][] MessageDetails() throws IOException {

            excel = new File("/home/workspace/TestCase/src/myPackage/standards.xls");
            fis = new FileInputStream(excel);
            wb = new HSSFWorkbook(fis);
            sheet = wb.getSheet("Sheet1");

            rowNum = sheet.getLastRowNum() + 1;
            colNum = sheet.getRow(0).getLastCellNum();
            data = new String[rowNum][colNum];
            for (i = 0; i < rowNum; i++) {
                rw = sheet.getRow(i);
                for (j = 0; j < colNum; j++) {
                    cell = rw.getCell(j);

                    System.out.println("Value is:" + data[i][j]);
                }
            }
            return data;
        }


Source: apache

Leave a Reply