Skip to content

Commit

Permalink
修复不自动行高的问题 [Issue #1869]
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangjiaju committed Sep 15, 2021
1 parent 6a17179 commit 56ab48e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -322,6 +323,7 @@ private Row createRowIfNecessary(Sheet sheet, Sheet cachedSheet, Integer lastRow
AnalysisCell analysisCell, boolean isOriginalCell) {
Row row = sheet.getRow(lastRowIndex);
if (row != null) {
checkRowHeight(analysisCell, fillConfig, isOriginalCell, row);
return row;
}
row = cachedSheet.getRow(lastRowIndex);
Expand Down Expand Up @@ -351,7 +353,8 @@ private void checkRowHeight(AnalysisCell analysisCell, FillConfig fillConfig, bo
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;
}
Expand Down Expand Up @@ -391,9 +394,9 @@ private List<AnalysisCell> readTemplateData(Map<String, List<AnalysisCell>> anal
/**
* 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
*/
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/org/apache/poi/hssf/usermodel/PoiHssfUtils.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
1 change: 1 addition & 0 deletions update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 56ab48e

Please sign in to comment.