From f8a52ab18bb5628d12a2e94842c73416373b116d Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Mon, 1 Nov 2021 10:27:07 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9pagecount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/excel/read/listener/PageReadListener.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java b/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java index a459818d..5ce3adf8 100644 --- a/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java +++ b/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java @@ -15,7 +15,7 @@ public class PageReadListener implements ReadListener { /** * Single handle the amount of data */ - public static final int BATCH_COUNT = 3000; + public static int BATCH_COUNT = 3000; /** * Temporary storage of data */ @@ -34,7 +34,6 @@ public class PageReadListener implements ReadListener { cachedData.add(data); if (cachedData.size() >= BATCH_COUNT) { consumer.accept(cachedData); - // 存储完成清理 list cachedData = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT); } } From 27d44c290a07a71ea569d34d9f518bce0b269fd8 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Mon, 1 Nov 2021 10:27:58 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9pagecount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alibaba/excel/read/listener/PageReadListener.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java b/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java index 5ce3adf8..c692bf10 100644 --- a/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java +++ b/src/main/java/com/alibaba/excel/read/listener/PageReadListener.java @@ -6,6 +6,8 @@ import java.util.function.Consumer; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.util.ListUtils; +import org.apache.commons.collections4.CollectionUtils; + /** * page read listener * @@ -40,7 +42,9 @@ public class PageReadListener implements ReadListener { @Override public void doAfterAllAnalysed(AnalysisContext context) { - consumer.accept(cachedData); + if (CollectionUtils.isNotEmpty(cachedData)) { + consumer.accept(cachedData); + } } } From c5ec482bfcac227ef08c7e2405a4ca2b70029bb5 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Wed, 3 Nov 2021 15:03:21 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9util=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alibaba/excel/util/BooleanUtils.java | 15 +++++++++++++-- .../java/com/alibaba/excel/util/ClassUtils.java | 17 ++++++++++++++--- .../java/com/alibaba/excel/util/FieldUtils.java | 17 ++++++++++++++--- .../java/com/alibaba/excel/util/FileUtils.java | 14 +++++++++++++- .../com/alibaba/excel/util/MemberUtils.java | 15 +++++++++++++-- .../java/com/alibaba/excel/util/Validate.java | 15 +++++++++++++-- 6 files changed, 80 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/alibaba/excel/util/BooleanUtils.java b/src/main/java/com/alibaba/excel/util/BooleanUtils.java index 18f6dd39..c01ab24b 100644 --- a/src/main/java/com/alibaba/excel/util/BooleanUtils.java +++ b/src/main/java/com/alibaba/excel/util/BooleanUtils.java @@ -1,9 +1,20 @@ package com.alibaba.excel.util; /** - * boolean util + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * - * @author Jiaju Zhuang + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Apache Software Foundation (ASF) */ public class BooleanUtils { diff --git a/src/main/java/com/alibaba/excel/util/ClassUtils.java b/src/main/java/com/alibaba/excel/util/ClassUtils.java index 82f78af2..f79dfdcc 100644 --- a/src/main/java/com/alibaba/excel/util/ClassUtils.java +++ b/src/main/java/com/alibaba/excel/util/ClassUtils.java @@ -38,10 +38,21 @@ import lombok.Setter; import net.sf.cglib.beans.BeanMap; /** - * Class utils + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * - * @author Jiaju Zhuang - **/ + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Apache Software Foundation (ASF) + */ public class ClassUtils { public static final Map, FieldCache> FIELD_CACHE = new ConcurrentHashMap<>(); diff --git a/src/main/java/com/alibaba/excel/util/FieldUtils.java b/src/main/java/com/alibaba/excel/util/FieldUtils.java index 367c6e55..0a825a7b 100644 --- a/src/main/java/com/alibaba/excel/util/FieldUtils.java +++ b/src/main/java/com/alibaba/excel/util/FieldUtils.java @@ -9,10 +9,21 @@ import com.alibaba.excel.metadata.NullObject; import net.sf.cglib.beans.BeanMap; /** - * Field utils + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * - * @author Jiaju Zhuang - **/ + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Apache Software Foundation (ASF) + */ public class FieldUtils { public static Class nullObjectClass = NullObject.class; diff --git a/src/main/java/com/alibaba/excel/util/FileUtils.java b/src/main/java/com/alibaba/excel/util/FileUtils.java index bc6b5d8a..41a4be0e 100644 --- a/src/main/java/com/alibaba/excel/util/FileUtils.java +++ b/src/main/java/com/alibaba/excel/util/FileUtils.java @@ -16,8 +16,20 @@ import org.apache.poi.util.DefaultTempFileCreationStrategy; import org.apache.poi.util.TempFile; /** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * - * @author jipengfei + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Apache Software Foundation (ASF) */ public class FileUtils { public static final String POI_FILES = "poifiles"; diff --git a/src/main/java/com/alibaba/excel/util/MemberUtils.java b/src/main/java/com/alibaba/excel/util/MemberUtils.java index 6bcfaac6..ea639f90 100644 --- a/src/main/java/com/alibaba/excel/util/MemberUtils.java +++ b/src/main/java/com/alibaba/excel/util/MemberUtils.java @@ -5,9 +5,20 @@ import java.lang.reflect.Member; import java.lang.reflect.Modifier; /** - * Member utils. + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * - * @author Jiaju Zhuang + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Apache Software Foundation (ASF) */ public class MemberUtils { diff --git a/src/main/java/com/alibaba/excel/util/Validate.java b/src/main/java/com/alibaba/excel/util/Validate.java index 6207bb1a..d407fc12 100644 --- a/src/main/java/com/alibaba/excel/util/Validate.java +++ b/src/main/java/com/alibaba/excel/util/Validate.java @@ -3,9 +3,20 @@ package com.alibaba.excel.util; import java.util.Objects; /** - * Validate + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * - * @author Jiaju Zhuang + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Apache Software Foundation (ASF) */ public class Validate { From 4b53acc00ba50e434c3d69e8eb9c8a27eaa70241 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Thu, 4 Nov 2021 17:51:40 +0800 Subject: [PATCH 4/6] =?UTF-8?q?*=20=E4=BF=AE=E5=A4=8D`HeadStyle`=E6=97=A0?= =?UTF-8?q?=E6=95=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metadata/holder/AbstractWriteHolder.java | 8 ++- .../core/annotation/AnnotationDataTest.java | 60 ++++++++++++++++++- .../AnnotationIndexAndNameDataTest.java | 3 + .../core/annotation/AnnotationStyleData.java | 33 ++++++++++ 4 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationStyleData.java diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java index 0b546703..016191ae 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java @@ -273,9 +273,11 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ @Override protected WriteCellStyle headCellStyle(CellWriteHandlerContext context) { - ExcelContentProperty excelContentProperty = context.getExcelContentProperty(); - return WriteCellStyle.build(excelContentProperty.getContentStyleProperty(), - excelContentProperty.getContentFontProperty()); + Head head = context.getHeadData(); + if (head == null) { + return null; + } + return WriteCellStyle.build(head.getHeadStyleProperty(), head.getHeadFontProperty()); } @Override diff --git a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataTest.java index 02bd3159..3523d453 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataTest.java @@ -4,31 +4,40 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import com.alibaba.easyexcel.test.core.StyleTestUtils; import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.util.DateUtils; +import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; /** * @author Jiaju Zhuang */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class AnnotationDataTest { private static File file07; private static File file03; private static File fileCsv; + private static File fileStyle07; + private static File fileStyle03; @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("annotation07.xlsx"); file03 = TestFileUtil.createNewFile("annotation03.xls"); + fileStyle07 = TestFileUtil.createNewFile("annotationStyle07.xlsx"); + fileStyle03 = TestFileUtil.createNewFile("annotationStyle03.xls"); fileCsv = TestFileUtil.createNewFile("annotationCsv.csv"); } @@ -47,10 +56,46 @@ public class AnnotationDataTest { readAndWrite(fileCsv); } + @Test + public void t11WriteStyle07() throws Exception { + writeStyle(fileStyle07); + } + + @Test + public void t12Write03() throws Exception { + writeStyle(fileStyle03); + } + + private void writeStyle(File file) throws Exception { + EasyExcel.write().file(file).head(AnnotationStyleData.class).sheet().doWrite(dataStyle()); + + Workbook workbook = WorkbookFactory.create(file); + Sheet sheet = workbook.getSheetAt(0); + + Row row0 = sheet.getRow(0); + Cell cell00 = row0.getCell(0); + Assert.assertArrayEquals(new byte[] {-1, 0, -1}, StyleTestUtils.getFillForegroundColor(cell00)); + Assert.assertArrayEquals(new byte[] {-1, -52, 0}, StyleTestUtils.getFontColor(cell00, workbook)); + Assert.assertEquals(40, StyleTestUtils.getFontHeightInPoints(cell00, workbook)); + + Cell cell01 = row0.getCell(1); + Assert.assertArrayEquals(new byte[] {-1, 0, 0}, StyleTestUtils.getFillForegroundColor(cell01)); + Assert.assertArrayEquals(new byte[] {0, -1, -1}, StyleTestUtils.getFontColor(cell01, workbook)); + Assert.assertEquals(20, StyleTestUtils.getFontHeightInPoints(cell01, workbook)); + + Row row1 = sheet.getRow(1); + Cell cell10 = row1.getCell(0); + Assert.assertArrayEquals(new byte[] {0, -52, -1}, StyleTestUtils.getFillForegroundColor(cell10)); + Assert.assertArrayEquals(new byte[] {0, 0, -1}, StyleTestUtils.getFontColor(cell10, workbook)); + Assert.assertEquals(50, StyleTestUtils.getFontHeightInPoints(cell10, workbook)); + Cell cell11 = row1.getCell(1); + Assert.assertArrayEquals(new byte[] {0, -128, 0}, StyleTestUtils.getFillForegroundColor(cell11)); + Assert.assertArrayEquals(new byte[] {-64, -64, -64}, StyleTestUtils.getFontColor(cell11, workbook)); + Assert.assertEquals(30, StyleTestUtils.getFontHeightInPoints(cell11, workbook)); + } + private void readAndWrite(File file) throws Exception { - EasyExcel.write().file(file).head(AnnotationData.class).sheet().doWrite(data()); - EasyExcel.read().file(file).head(AnnotationData.class).registerReadListener(new AnnotationDataListener()) - .sheet().doRead(); + EasyExcel.write().file(file).head(AnnotationData.class).sheet().doWrite(dataStyle()); if (file == fileCsv) { return; @@ -67,6 +112,15 @@ public class AnnotationDataTest { Assert.assertEquals(2000, row1.getHeight(), 0); } + private List dataStyle() throws Exception { + List list = new ArrayList<>(); + AnnotationStyleData data = new AnnotationStyleData(); + data.setString("string"); + data.setString1("string1"); + list.add(data); + return list; + } + private List data() throws Exception { List list = new ArrayList<>(); AnnotationData data = new AnnotationData(); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java index 937cf665..8b34c2a1 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java @@ -8,13 +8,16 @@ import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; import org.junit.BeforeClass; +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; /** * Annotation data test * * @author Jiaju Zhuang */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class AnnotationIndexAndNameDataTest { private static File file07; diff --git a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationStyleData.java b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationStyleData.java new file mode 100644 index 00000000..5b00e1ac --- /dev/null +++ b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationStyleData.java @@ -0,0 +1,33 @@ +package com.alibaba.easyexcel.test.core.annotation; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ContentFontStyle; +import com.alibaba.excel.annotation.write.style.ContentStyle; +import com.alibaba.excel.annotation.write.style.HeadFontStyle; +import com.alibaba.excel.annotation.write.style.HeadStyle; +import com.alibaba.excel.enums.poi.FillPatternTypeEnum; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +/** + * @author Jiaju Zhuang + */ +@Getter +@Setter +@EqualsAndHashCode +@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 10) +@HeadFontStyle(fontHeightInPoints = 20, color = 15) +@ContentStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 17) +@ContentFontStyle(fontHeightInPoints = 30, color = 22) +public class AnnotationStyleData { + @ExcelProperty("字符串") + @HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 14) + @HeadFontStyle(fontHeightInPoints = 40, color = 51) + @ContentStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 40) + @ContentFontStyle(fontHeightInPoints = 50, color = 12) + private String string; + @ExcelProperty("字符串1") + private String string1; +} From 530ab5da166ec4900c919c2fbc16d87ec676388b Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Thu, 4 Nov 2021 17:51:43 +0800 Subject: [PATCH 5/6] =?UTF-8?q?*=20=E4=BF=AE=E5=A4=8D`HeadStyle`=E6=97=A0?= =?UTF-8?q?=E6=95=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/update.md b/update.md index f1f90470..3e73f949 100644 --- a/update.md +++ b/update.md @@ -1,3 +1,6 @@ +# 3.0.3 +* 修复`HeadStyle`无效的bug + # 3.0.2 * 大幅提升读写性能 * 修复列宽注解没用的bug [Issue #2151](https://github.com/alibaba/easyexcel/issues/2151) From f0d86c84794cb5403f07740271f52541833be2de Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Thu, 4 Nov 2021 20:01:34 +0800 Subject: [PATCH 6/6] =?UTF-8?q?*=20=E4=BF=AE=E5=A4=8D`HeadStyle`=E6=97=A0?= =?UTF-8?q?=E6=95=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4fa394fb..ebba173e 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都 com.alibaba easyexcel - 3.0.2 + 3.0.3 ``` diff --git a/pom.xml b/pom.xml index 00bae497..c5aec18c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.alibaba easyexcel - 3.0.2 + 3.0.3 jar easyexcel