Java excel:获取行中的下一个单元格 [英] Java excel: Get next cell in the row
本文介绍了Java excel:获取行中的下一个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在找到字符串后获取 a 中下一个单元格的值.假设我将 A1 作为包含我的搜索字符串here"的单元格,我试图获取行中 A1 之后的下一个单元格的内容.
I am trying to get the value of the next cell in a after a string is found. Let's say I get A1 as the cell that contains my search string "here", I am trying to get the contents of the next cell after A1 in the row.
private static String findRow(XSSFSheet sheet, String cellContent) {
for (Row row : sheet) {
for (Cell cell : row) {
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
if (cell.getRichStringCellValue().getString().trim().equals(cellContent)) {
cell = cell.getNextRowCell //made up method
return cell.getStringCellValue();
}
}
}
推荐答案
I figured it out.
private static String getNextRow(XSSFSheet sheet, String cellContent) {
Iterator<Row> itr = sheet.iterator();
while (itr.hasNext()) {
Row row = itr.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
if (cell.getRichStringCellValue().getString().trim()
.equals(cellContent)) {
row = itr.next();
int val = cell.getColumnIndex();
cell = row.getCell(val);
String srow = cell.getStringCellValue();
return srow;
}
}
}
}
return null;
}
这篇关于Java excel:获取行中的下一个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文