From 234fc2d53e5bc89b9d01799942fa818cbbcdc814 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Fri, 17 Sep 2021 17:21:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A1=AB=E5=85=85=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E4=B8=8D=E8=87=AA=E5=8A=A8=E7=BB=A7=E6=89=BF=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=20[Issue=20#1710]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executor/ExcelWriteFillExecutor.java | 18 +++-- .../excel/write/metadata/fill/FillConfig.java | 68 ++++++------------- .../easyexcel/test/temp/Lock2Test.java | 3 +- update.md | 1 + 4 files changed, 32 insertions(+), 58 deletions(-) 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 3c2268cd..af3f6c24 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java @@ -84,7 +84,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor { data = new HashMap(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); + } } } diff --git a/src/main/java/com/alibaba/excel/write/metadata/fill/FillConfig.java b/src/main/java/com/alibaba/excel/write/metadata/fill/FillConfig.java index a5bbe917..8fdb240a 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/fill/FillConfig.java +++ b/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; } } diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java b/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java index 2b229d2d..e2f5d0ec 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java +++ b/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 list = EasyExcel.read("/Users/zhuangjiaju/Downloads/olay (1).xlsx").sheet(0).doReadSync(); + List 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)); diff --git a/update.md b/update.md index 2b7e082e..a2296684 100644 --- a/update.md +++ b/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