I know that Excel sheets are row based rather than column based and when I fetch information row based its working fine using Apache POI but In order to do some statistical analysis I need to extract values in a column of an Excel sheet.

As I need to get max and min values of different columns and generate random numbers using these values, so without picking up individual columns, the only other option is to iterate over rows and columns to get the values and compare one by one, which doesn"t sound all that time-efficient.

Any ideas on how to tackle this problem?

Find the snippet to fetch the columns from Excel sheet using Apache POI.

List<Double> values = new ArrayList<Double>();

for(Row r : sheet) {

Cell c = r.getCell(columnNumber);

if(c != null) {

if(c.getCellType() == Cell.CELL_TYPE_NUMERIC) {

valuesadd(c.getNumericCellValue());

} else if(c.getCellType() == Cell.CELL_TYPE_FORMULA && c.getCachedFormulaResultType() == Cell.CELL_TYPE_NUMERIC) {

valuesadd(c.getNumericCellValue());

}

}

}

Note : The only way to get all the values in a column is to look at each row in turn. There's no quicker way to get at the columns, because cells in a column aren't stored together.