在 Apache POI API 中提取电子表格列中的数据 [英] Extracting data in spreadsheet columns in Apache POI API

查看:47
本文介绍了在 Apache POI API 中提取电子表格列中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只想确定一件事.

Apache POI API 是否有任何内置集合/对象,如行和单元格,用于电子表格中的列?

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?

推荐答案

excel 格式是基于行的而不是基于列的 - 文件是按行中的每个单元格按顺序写入的,然后是几位行信息,然后下一行的单元格按顺序等

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

这篇关于在 Apache POI API 中提取电子表格列中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆