java - 如何在使用 POI 迭代 excel 文件时跳过空白单元格值并选择下一个单元格
问题描述
我正在尝试解析一个excel文件,我必须在其中并行读取标题和数据。我需要检查,如果找到空白单元格,则在解析标题时我必须立即跳过单元格并获取下一个值,但这不能在另一次迭代中完成。我在这里尝试过,但在我的代码中,我在跳过的单元格中没有得到任何值,
while (cellIterator.hasNext() && cellIteratorTotal.hasNext()) {
cellCount++;
Cell currentCell = cellIterator.next();
Cell currentCellTotal = cellIteratorTotal.next();
currentRow = sheet.getRow(currentRowTotal.getRowNum() + 1); // here i am trying to hold the current row value
String cellValue = excelManager.evalCell(currentCell);
String cellValueTotal = excelManager.evalCell(currentCellTotal);
if(currentRow!=null) {
String value = currentRow.getCell(currentCellTotal.getColumnIndex(), Row.CREATE_NULL_AS_BLANK).getStringCellValue(); // here i am trying to get the next cell value
}
任何人都可以帮助我正确的方法吗,在此先感谢
解决方案
下面的代码可以帮助你。请检查。if (cell == null || c.getCellType() == Cell.CELL_TYPE_BLANK) {
}
推荐阅读
- android - 如何更改 ListView 项目的高度?
- python - 自定义提交无效 JSON 数据时的错误响应
- java - (有点解决但仍然感谢更好的答案) Android Studio:如何识别 PDF 文件中的某些特殊页面?
- python - python根据创建时间排序文件路径
- ios - 由于版本较低错误,无法在设备上启动用 Swift 编写的 iOS 应用程序
- html - 当我“检查”不在我所写内容中的任何位置并导致文本颜色“错误”的页面时出现代码,我该如何解决这个问题?
- javascript - 如何将 API 响应从子组件传递到另一个嵌套组件?
- reactjs - 使用基本身份验证响应简单的 REST API
- elasticsearch - 聚合(一个字段中有多个值)elasticsearch
- discord - Discord.js 如何使用机器人提及和设置前缀作为前缀