小编Jsk*_*Jsk的帖子

如何使用Apache POI在Excel工作表中搜索特定日期?

我一直在使用给出的示例代码来搜索工作表的内容:

Sheet sheet1 = wb.getSheetAt(0);
for (Row row : sheet1) {
 for (Cell cell : row) {
  CellReference cellRef = new CellReference(row.getRowNum(), cell.getCellNum());
  System.out.print(cellRef.formatAsString());
  System.out.print(" - ");

  switch(cell.getCellType()) {
      case Cell.CELL_TYPE_STRING:
        System.out.println(cell.getRichStringCellValue().getString());
        break;
      case Cell.CELL_TYPE_NUMERIC:
        if(DateUtil.isCellDateFormatted(cell)) {
          System.out.println(cell.getDateCellValue());
        } else {
          System.out.println(cell.getNumericCellValue());
        }
        break;
      case Cell.CELL_TYPE_BOOLEAN:
        System.out.println(cell.getBooleanCellValue());
        break;
      case Cell.CELL_TYPE_FORMULA:
        System.out.println(cell.getCellFormula());
        break;
      default:
        System.out.println();
  }
 }
Run Code Online (Sandbox Code Playgroud)

}

But can't find a way to properly compare the dates extracted from the sheet with a given date. I've tried using a data …

java excel poi-hssf apache-poi

5
推荐指数
1
解决办法
3209
查看次数

标签 统计

apache-poi ×1

excel ×1

java ×1

poi-hssf ×1