使用Apache POI如何读取特定的Excel列 [英] Using apache poi how to read a specific excel column

查看:1128
本文介绍了使用Apache POI如何读取特定的Excel列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用的Apache POI有Excel中的一个问题。我可以在读取的行数,但有时我在一个情况下,我想只能读取特定列。

I'm having a problem in excel while using Apache poi. I can read across rows, but sometimes I'm in a situation where I would like to read a particular column only.

那么,它可以读取任何特定列象只A仅列或列'C'只。

So is it possible to read any particular column like only the 'A' column only or the column 'C' only.

我用java语言这一点。

I'm using java language for this.

推荐答案

heikkim是正确的,下面是一些示例code改编自一些code我有:

heikkim is right, here is some sample code adapted from some code I have:

for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
  row = sheet.getRow(rowIndex);
  if (row != null) {
    String key = null;
    for (int colIndex = 0; colIndex < cols; colIndex++) {
      if (colIndex == theColIndexYouWant) {
        cell = row.getCell(colIndex);
        if (cell != null) {
          key = cell.getStringCellValue();
        }
    }
    // Do something with the key here...
  }
}

对于COLS使用类似 row.getPhysicalNumberOfCells()

这篇关于使用Apache POI如何读取特定的Excel列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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