From 8b3e27cbc244bc5e09ea1acd8a0a0546927e063d Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期日, 08 十月 2023 11:43:20 +0800 Subject: [PATCH] 新版excel优化 --- src/main/java/com/hx/util/ExcelUtil.java | 49 +++++++++++++++++++++++++------------------------ 1 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/hx/util/ExcelUtil.java b/src/main/java/com/hx/util/ExcelUtil.java index ee0af02..9c789f8 100644 --- a/src/main/java/com/hx/util/ExcelUtil.java +++ b/src/main/java/com/hx/util/ExcelUtil.java @@ -976,33 +976,34 @@ cell = row.getCell(j); if (cell == null) { arrayString.add(""); - } - if (cell.getCellType() == CellType.NUMERIC) { - isData = true; - format = cell.getCellStyle().getDataFormat(); - if (format == 14 || format == 31 || format == 57 || format == 58) { - //鏃ユ湡锛堜腑鏂囨椂闂存牸寮忕殑锛� - d = cell.getDateCellValue(); - formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); - arrayString.add(formater.format(d)); - } else if (HSSFDateUtil.isCellDateFormatted(cell)) { - d = cell.getDateCellValue(); - formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); - arrayString.add(formater.format(d)); - } else { - if (CellType.STRING == cell.getCellType()) { - arrayString.add(cell.getStringCellValue()); - } else if (CellType.FORMULA == cell.getCellType()) { - arrayString.add(cell.getCellFormula()); + }else{ + if (cell.getCellType() == CellType.NUMERIC) { + isData = true; + format = cell.getCellStyle().getDataFormat(); + if (format == 14 || format == 31 || format == 57 || format == 58) { + //鏃ユ湡锛堜腑鏂囨椂闂存牸寮忕殑锛� + d = cell.getDateCellValue(); + formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + arrayString.add(formater.format(d)); + } else if (HSSFDateUtil.isCellDateFormatted(cell)) { + d = cell.getDateCellValue(); + formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + arrayString.add(formater.format(d)); } else { - arrayString.add(cell.getStringCellValue().trim()); + if (CellType.STRING == cell.getCellType()) { + arrayString.add(cell.getStringCellValue()); + } else if (CellType.FORMULA == cell.getCellType()) { + arrayString.add(cell.getCellFormula()); + } else { + arrayString.add(cell.getStringCellValue().trim()); + } } + } else if (cell.getCellType() == CellType.BLANK) { + arrayString.add(""); + } else { // 濡傛灉EXCEL琛ㄦ牸涓殑鏁版嵁绫诲瀷涓哄瓧绗︿覆鍨� + isData = true; + arrayString.add(cell.getStringCellValue().trim()); } - } else if (cell.getCellType() == CellType.BLANK) { - arrayString.add(""); - } else { // 濡傛灉EXCEL琛ㄦ牸涓殑鏁版嵁绫诲瀷涓哄瓧绗︿覆鍨� - isData = true; - arrayString.add(cell.getStringCellValue().trim()); } } if (isData) { -- Gitblit v1.8.0