Skip to content

Commit

Permalink
修改填充可以不自动继承样式 [Issue #1710]
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangjiaju committed Sep 17, 2021
1 parent 8c95bfc commit 234fc2d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void fill(Object data, FillConfig fillConfig) {
data = new HashMap<String, Object>(16);
}
if (fillConfig == null) {
fillConfig = FillConfig.builder().build(true);
fillConfig = FillConfig.builder().build();
}
fillConfig.init();

Expand Down Expand Up @@ -301,9 +301,11 @@ private Cell getOneCell(AnalysisCell analysisCell, FillConfig fillConfig) {
if (isOriginalCell) {
collectionFieldStyleMap.put(analysisCell, cell.getCellStyle());
} else {
CellStyle cellStyle = collectionFieldStyleMap.get(analysisCell);
if (cellStyle != null) {
cell.setCellStyle(cellStyle);
if (fillConfig.getAutoStyle()) {
CellStyle cellStyle = collectionFieldStyleMap.get(analysisCell);
if (cellStyle != null) {
cell.setCellStyle(cellStyle);
}
}
}
return cell;
Expand Down Expand Up @@ -359,9 +361,11 @@ private void checkRowHeight(AnalysisCell analysisCell, FillConfig fillConfig, bo
collectionRowHeightCache.put(currentUniqueDataFlag, row.getHeight());
return;
}
Short rowHeight = collectionRowHeightCache.get(currentUniqueDataFlag);
if (rowHeight != null) {
row.setHeight(rowHeight);
if (fillConfig.getAutoStyle()) {
Short rowHeight = collectionRowHeightCache.get(currentUniqueDataFlag);
if (rowHeight != null) {
row.setHeight(rowHeight);
}
}
}

Expand Down
68 changes: 19 additions & 49 deletions src/main/java/com/alibaba/excel/write/metadata/fill/FillConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

import com.alibaba.excel.enums.WriteDirectionEnum;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* Fill config
*
* @author Jiaju Zhuang
**/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FillConfig {
private WriteDirectionEnum direction;
/**
Expand All @@ -16,23 +25,15 @@ public class FillConfig {
* say the whole file will be stored in memory.
*/
private Boolean forceNewRow;
private boolean hasInit;

public WriteDirectionEnum getDirection() {
return direction;
}

public void setDirection(WriteDirectionEnum direction) {
this.direction = direction;
}

public Boolean getForceNewRow() {
return forceNewRow;
}
/**
* Automatically inherit style
*
* default true.
*/
private Boolean autoStyle;

public void setForceNewRow(Boolean forceNewRow) {
this.forceNewRow = forceNewRow;
}
private boolean hasInit;

public void init() {
if (hasInit) {
Expand All @@ -44,40 +45,9 @@ public void init() {
if (forceNewRow == null) {
forceNewRow = Boolean.FALSE;
}
hasInit = true;
}

public static FillConfigBuilder builder() {
return new FillConfigBuilder();
}

public static class FillConfigBuilder {
private FillConfig fillConfig;

FillConfigBuilder() {
this.fillConfig = new FillConfig();
}

public FillConfigBuilder direction(WriteDirectionEnum direction) {
fillConfig.setDirection(direction);
return this;
}

public FillConfigBuilder forceNewRow(Boolean forceNewRow) {
fillConfig.setForceNewRow(forceNewRow);
return this;
if (autoStyle == null) {
autoStyle = Boolean.TRUE;
}

public FillConfig build() {
return build(true);
}

public FillConfig build(boolean autoInit) {
if (autoInit) {
fillConfig.init();
}
return fillConfig;
}

hasInit = true;
}
}
3 changes: 1 addition & 2 deletions src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ public class Lock2Test {

@Test
public void test() throws Exception {
assert 1 != 1;
// File file = TestFileUtil.readUserHomeFile("test/test4.xlsx");
// File file = TestFileUtil.readUserHomeFile("test/test6.xls");
File file = new File("/Users/zhuangjiaju/IdeaProjects/easyexcel/src/test/resources/converter/converter07.xlsx");

List<Object> list = EasyExcel.read("/Users/zhuangjiaju/Downloads/olay (1).xlsx").sheet(0).doReadSync();
List<Object> list = EasyExcel.read("/Users/zhuangjiaju/Downloads/1 (2).xlsx").sheet(0).doReadSync();
LOGGER.info("数据:{}", list.size());
for (Object data : list) {
LOGGER.info("返回数据:{}", CollectionUtils.size(data));
Expand Down
1 change: 1 addition & 0 deletions update.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* 修复头和数据对象不一致会覆盖的问题 [Issue #1870](https://github.com/alibaba/easyexcel/issues/1870)
* 修复忽略字段后可能排序不一致的问题
* 修改填充时,无法使用生成的模板 [Issue #1552](https://github.com/alibaba/easyexcel/issues/1552)
* 修改填充可以不自动继承样式 [Issue #1710](https://github.com/alibaba/easyexcel/issues/1710)


# 2.2.11
Expand Down

0 comments on commit 234fc2d

Please sign in to comment.