From 756acbd7d971fbeebe224bdedfdd1a3e0a195dc2 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期一, 18 九月 2023 15:10:36 +0800 Subject: [PATCH] 新版excel优化 --- src/main/java/com/hx/util/ExcelUtil.java | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hx/util/ExcelUtil.java b/src/main/java/com/hx/util/ExcelUtil.java index 9a59522..57bc636 100644 --- a/src/main/java/com/hx/util/ExcelUtil.java +++ b/src/main/java/com/hx/util/ExcelUtil.java @@ -1,6 +1,5 @@ package com.hx.util; -import com.alibaba.fastjson.JSON; import com.hx.exception.TipsException; import com.monitorjbl.xlsx.StreamingReader; import org.apache.poi.hssf.usermodel.*; @@ -867,6 +866,7 @@ /** * 鏂扮増璇诲彇Excel锛屽彧鏀寔2007浠ヤ笂鐗堟湰锛屼篃灏辨槸xslx鏍煎紡 + * 鏀寔澶ф暟鎹噺 * @param file 鏂囦欢 * @return 鏁版嵁 */ @@ -893,6 +893,7 @@ /** * 鏂扮増璇诲彇Excel锛屽彧鏀寔2007浠ヤ笂鐗堟湰锛屼篃灏辨槸xslx鏍煎紡 + * 鏀寔澶ф暟鎹噺 * @param file 鏂囦欢 * @return 鏁版嵁 */ @@ -920,6 +921,7 @@ /** * 鏂扮増璇诲彇Excel锛屽彧鏀寔2007浠ヤ笂鐗堟湰锛屼篃灏辨槸xslx鏍煎紡 + * 鏀寔澶ф暟鎹噺 * @param file 鏂囦欢 * @return 鏁版嵁 */ @@ -953,15 +955,25 @@ Date d; DateFormat formater; Sheet sheet; + Cell cell; //閬嶅巻鎵�鏈夌殑sheet for(int i=0;i<book.getNumberOfSheets();i++) { sheet = book.getSheetAt(i); + //鍒楁暟 + Integer arrange = null; //閬嶅巻鎵�鏈夌殑琛� for (Row row : sheet) { + if(row == null){ + continue; + } isData = false; arrayString = new ArrayList<>(); + if(arrange == null){ + arrange = row.getPhysicalNumberOfCells(); + } //閬嶅巻鎵�鏈夌殑鍒� - for (Cell cell : row) { + for (int j = 0;j<arrange;j++) { + cell = row.getCell(j); if (cell == null) { arrayString.add(""); } else if (cell.getCellType() == CellType.NUMERIC) { -- Gitblit v1.8.0