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

查看:148
本文介绍了使用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 ...
    }
  }
}

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

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

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