1

Just want to make sure one thing.

Does the Apache POI API have any built-in collection/object, like row and cell, for a column in a spreadsheet?

Or do I have to build one myself and add all the cells in the column there to do the sorting etc? Is there any other better way to do it?

eboix
  • 5,113
  • 1
  • 27
  • 38
  • 1
    Maybe you should check the Apache POI: http://poi.apache.org/apidocs/index.html. There is a Column class:org.apache.poi.ss.formula.functions.Column and a ColumnHelper class. – eboix Dec 21 '11 at 19:23

1 Answers1

2

The excel format is row based not column based - the file is written with each cell in a row in order, followed by a few bits of row info, then the cells of the next row in order etc.

So, if you want to do something on a column basis, you'll need to collect the cells up yourself. It'd likely be something like:

int columnWanted = 3;
List<Cell> cells = new ArrayList<Cell>();

for (Row row : sheet) {
   Cell c = row.getCell(columnWanted);
   if (c == null || c.getCellType == Cell.CELL_TYPE_BLANK) {
      // Nothing in the cell in this row, skip it
   } else {
      cells.add(c);
   }
}

// Now use the cells array
Gagravarr
  • 47,320
  • 10
  • 111
  • 156