Extracting data in spreadsheet columns in Apache POI API

本小妞迷上赌 提交于 2019-12-24 08:39:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!