Browse Source

修改填充可以不自动继承样式 [Issue #1710]

pull/2077/head
Jiaju Zhuang 3 years ago
parent
commit
234fc2d53e
  1. 18
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
  2. 68
      src/main/java/com/alibaba/excel/write/metadata/fill/FillConfig.java
  3. 3
      src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
  4. 1
      update.md

18
src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java

@ -84,7 +84,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
data = new HashMap<String, Object>(16);
}
if (fillConfig == null) {
fillConfig = FillConfig.builder().build(true);
fillConfig = FillConfig.builder().build();
}
fillConfig.init();
@ -301,9 +301,11 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
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;
@ -359,9 +361,11 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
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);
}
}
}

68
src/main/java/com/alibaba/excel/write/metadata/fill/FillConfig.java

@ -2,11 +2,20 @@ package com.alibaba.excel.write.metadata.fill;
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;
/**
@ -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) {
@ -44,40 +45,9 @@ public class FillConfig {
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
src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java

@ -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));

1
update.md

@ -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

Loading…
Cancel
Save