diff --git a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java index 1c45c49d..9041419a 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java @@ -28,6 +28,7 @@ import com.alibaba.excel.write.metadata.fill.FillWrapper; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import org.apache.commons.collections4.CollectionUtils; +import org.apache.poi.hssf.usermodel.PoiHssfUtils; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellType; @@ -322,6 +323,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { AnalysisCell analysisCell, boolean isOriginalCell) { Row row = sheet.getRow(lastRowIndex); if (row != null) { + checkRowHeight(analysisCell, fillConfig, isOriginalCell, row); return row; } row = cachedSheet.getRow(lastRowIndex); @@ -351,7 +353,8 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { if (!analysisCell.getFirstRow() || !WriteDirectionEnum.VERTICAL.equals(fillConfig.getDirection())) { return; } - if (isOriginalCell) { + // fix https://github.com/alibaba/easyexcel/issues/1869 + if (isOriginalCell && PoiHssfUtils.customHeight(row)) { collectionRowHeightCache.put(currentUniqueDataFlag, row.getHeight()); return; } @@ -391,9 +394,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { /** * To prepare data * - * @param cell cell - * @param rowIndex row index - * @param columnIndex column index + * @param cell cell + * @param rowIndex row index + * @param columnIndex column index * @param firstRowCache first row cache * @return Returns the data that the cell needs to replace */ diff --git a/src/main/java/org/apache/poi/hssf/usermodel/PoiHssfUtils.java b/src/main/java/org/apache/poi/hssf/usermodel/PoiHssfUtils.java new file mode 100644 index 00000000..80f7f3b8 --- /dev/null +++ b/src/main/java/org/apache/poi/hssf/usermodel/PoiHssfUtils.java @@ -0,0 +1,37 @@ +package org.apache.poi.hssf.usermodel; + +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.util.BitField; +import org.apache.poi.util.BitFieldFactory; +import org.apache.poi.xssf.usermodel.XSSFRow; + +/** + * utils + * + * @author Jiaju Zhuang + */ +public class PoiHssfUtils { + + /** + * Whether to customize the height + */ + public static final BitField CUSTOM_HEIGHT = BitFieldFactory.getInstance(0x640); + + /** + * Whether to customize the height + * + * @param row + * @return + */ + public static boolean customHeight(Row row) { + if (row instanceof XSSFRow) { + XSSFRow xssfRow = (XSSFRow)row; + return xssfRow.getCTRow().getCustomHeight(); + } + if (row instanceof HSSFRow) { + HSSFRow hssfRow = (HSSFRow)row; + return CUSTOM_HEIGHT.getValue(hssfRow.getRowRecord().getOptionFlags()) == 1; + } + return false; + } +} diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/issue1662/Issue1662Test.java b/src/test/java/com/alibaba/easyexcel/test/temp/issue1662/Issue1662Test.java index 8fa5a842..cea7e5ee 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/issue1662/Issue1662Test.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/issue1662/Issue1662Test.java @@ -1,14 +1,16 @@ package com.alibaba.easyexcel.test.temp.issue1662; -import com.alibaba.easyexcel.test.util.TestFileUtil; -import com.alibaba.excel.EasyExcel; -import org.junit.Test; - - import java.util.ArrayList; import java.util.Date; import java.util.List; +import com.alibaba.easyexcel.test.util.TestFileUtil; +import com.alibaba.excel.EasyExcel; + +import org.junit.Ignore; +import org.junit.Test; + +@Ignore public class Issue1662Test { @Test public void test1662() { diff --git a/update.md b/update.md index c2cbf89c..45f4a227 100644 --- a/update.md +++ b/update.md @@ -20,6 +20,7 @@ * 修复无对象读 返回map的size可能会头的size不一致 [Issue #2014](https://github.com/alibaba/easyexcel/issues/2014) * 修复合并头可能异常的bug [Issue #1662](https://github.com/alibaba/easyexcel/issues/1662) * 修复填充调用横向样式策略报错 [Issue #1651](https://github.com/alibaba/easyexcel/issues/1651) +* 修复不自动行高的问题 [Issue #1869](https://github.com/alibaba/easyexcel/issues/1869) # 2.2.10