'Reading 2D double array in Excel Using Apache POI

I am trying to make use of Apache POI to read an excel file and convert it to a 2-dimensional object array. Attached is the code section.

    Workbook workbook = new XSSFWorkbook(inputStream);
    Sheet firstSheet = workbook.getSheetAt(1);
    int numRows = 3;
    int cols = 5;
    double[][] excelData = new double[numRows][cols];
    for (int i = 1; i < numRows; i++) {
        Row row = firstSheet.getRow(i);
        if (row != null) {
            for (int j = 1; j < cols; j++) {
                Cell cell = row.getCell(j);
                if (cell != null) {
                    try {
                        excelData[i][j] = cell.getNumericCellValue();
                    } catch (IllegalStateException e) {
                        System.out.println("Cell data is not a double");
                    }
                }
            }
        }
    }
    workbook.close();
    inputStream.close();
    return excelData;
}

enter image description here This is my excel sheet and I want to "just" read the blue part of it as a 2d array, but after running the code the first row and column all are zero and I don't want it, appreciate your help on how can quickly pull out all the zeros enter image description here.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source