diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/util/PoiUtils.java b/easyexcel-core/src/main/java/com/alibaba/excel/util/PoiUtils.java index 2989b22b..0b70a487 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/util/PoiUtils.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/util/PoiUtils.java @@ -1,6 +1,7 @@ package com.alibaba.excel.util; import com.alibaba.excel.exception.ExcelRuntimeException; + import org.apache.poi.hssf.record.RowRecord; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.ss.usermodel.Row; @@ -22,7 +23,7 @@ public class PoiUtils { */ public static final BitField CUSTOM_HEIGHT = BitFieldFactory.getInstance(0x640); - private static Field ROW_RECORD_FIELD; + private static final Field ROW_RECORD_FIELD = FieldUtils.getField(HSSFRow.class, "row", true); /** * Whether to customize the height @@ -32,30 +33,17 @@ public class PoiUtils { */ public static boolean customHeight(Row row) { if (row instanceof XSSFRow) { - XSSFRow xssfRow = (XSSFRow) row; + XSSFRow xssfRow = (XSSFRow)row; return xssfRow.getCTRow().getCustomHeight(); } if (row instanceof HSSFRow) { - HSSFRow hssfRow = (HSSFRow) row; + HSSFRow hssfRow = (HSSFRow)row; try { - if (ROW_RECORD_FIELD == null) { - initRowRecordField(); - } - RowRecord record = (RowRecord) ROW_RECORD_FIELD.get(hssfRow); + RowRecord record = (RowRecord)ROW_RECORD_FIELD.get(hssfRow); return CUSTOM_HEIGHT.getValue(record.getOptionFlags()) == 1; } catch (IllegalAccessException ignore) { } } return false; } - - - private static void initRowRecordField() { - try { - ROW_RECORD_FIELD = HSSFRow.class.getDeclaredField("row"); - ROW_RECORD_FIELD.setAccessible(true); - } catch (NoSuchFieldException e) { - throw new ExcelRuntimeException(e); - } - } } diff --git a/update.md b/update.md index faabba6a..76f8aa1a 100644 --- a/update.md +++ b/update.md @@ -5,6 +5,7 @@ * xlsx存在隐藏字符时需要忽略,确保和展示看到的一样 * 新增`commons-io` 2.11.0 包 * 在`easyexcel-parent` 包中移除测试包的`dependencyManagement` +* 删除`org.apache.poi.hssf.usermodel.PoiUtils.java`, 使用反射获取 [Issue #2804](https://github.com/alibaba/easyexcel/issues/2804) # 3.2.1