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

查看:53
本文介绍了使用 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 the Java language for this.

推荐答案

heikkim 是对的,这里有一些示例代码改编自我的一些代码:

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

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
...
for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
  row = sheet.getRow(rowIndex);
  if (row != null) {
    Cell cell = row.getCell(colIndex);
    if (cell != null) {
      // Found column and there is value in the cell.
      cellValueMaybeNull = cell.getStringCellValue();
      // Do something with the cellValueMaybeNull here ...
      // break; ???
    }
  }
}

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

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

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