问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/8595016/extracting-data-in-spreadsheet-columns-in-apache-poi-api