我在使用 Apache POI 时遇到 Excel 问题。我可以跨行读取,但有时我只想读取特定列。
那么是否可以读取任何特定列,例如仅读取“A”列或仅读取“C”列。
我正在使用Java为此的语言。
heikkim 是对的,这里是一些示例代码,改编自我的一些代码:
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; ???
}
}
}
For the colCount
使用类似的东西row.getPhysicalNumberOfCells()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)