From 8368d37338e76ac519ddf89d63d9f45e0478628e Mon Sep 17 00:00:00 2001 From: dota17 Date: Tue, 19 May 2020 19:30:36 +0800 Subject: [PATCH] Improved the code --- ...therData.java => AnnotationStyleData.java} | 7 +++-- .../SimpleVerticalCellStyleStrategy.java | 6 ++-- .../test/core/style/StyleDataTest.java | 30 +++++++++---------- 3 files changed, 22 insertions(+), 21 deletions(-) rename src/test/java/com/alibaba/easyexcel/test/core/style/{StyleOtherData.java => AnnotationStyleData.java} (70%) diff --git a/src/test/java/com/alibaba/easyexcel/test/core/style/StyleOtherData.java b/src/test/java/com/alibaba/easyexcel/test/core/style/AnnotationStyleData.java similarity index 70% rename from src/test/java/com/alibaba/easyexcel/test/core/style/StyleOtherData.java rename to src/test/java/com/alibaba/easyexcel/test/core/style/AnnotationStyleData.java index 8c0383d2..dd5dac60 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/style/StyleOtherData.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/style/AnnotationStyleData.java @@ -9,9 +9,10 @@ import lombok.Data; * @author Pengliang Zhao */ @Data -public class StyleOtherData { - @ContentStyle(dataFormat = (short)1, rotation = (short)1, indent = (short)1, leftBorderColor = (short)1, rightBorderColor = (short)1, - topBorderColor = (short)1, bottomBorderColor = (short)1, fillForegroundColor = (short)1, fillBackgroundColor = (short)1) +public class AnnotationStyleData { + @ContentStyle(dataFormat = (short)1, rotation = (short)1, indent = (short)1, leftBorderColor = (short)1, + rightBorderColor = (short)1, topBorderColor = (short)1, bottomBorderColor = (short)1, + fillForegroundColor = (short)1, fillBackgroundColor = (short)1) @ContentFontStyle(fontHeightInPoints = (short)1, color = (short)1, typeOffset = (short)1, charset = (short)1) @ExcelProperty("字符串") private String string; diff --git a/src/test/java/com/alibaba/easyexcel/test/core/style/SimpleVerticalCellStyleStrategy.java b/src/test/java/com/alibaba/easyexcel/test/core/style/SimpleVerticalCellStyleStrategy.java index c99de9d5..9f4d3ac2 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/style/SimpleVerticalCellStyleStrategy.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/style/SimpleVerticalCellStyleStrategy.java @@ -17,13 +17,13 @@ import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy; * @author Pengliang Zhao */ public class SimpleVerticalCellStyleStrategy extends AbstractVerticalCellStyleStrategy { - private StyleProperty styleProperty = StyleProperty.build(StyleOtherData.class.getAnnotation(ContentStyle.class)); - private FontProperty fontProperty = FontProperty.build(StyleOtherData.class.getAnnotation(ContentFontStyle.class)); + private StyleProperty styleProperty = StyleProperty.build(AnnotationStyleData.class.getAnnotation(ContentStyle.class)); + private FontProperty fontProperty = FontProperty.build(AnnotationStyleData.class.getAnnotation(ContentFontStyle.class)); @Override protected WriteCellStyle headCellStyle(Head head) { WriteCellStyle writeCellStyle = WriteCellStyle.build(styleProperty, fontProperty); - if(head.getColumnIndex() == 0) { + if (head.getColumnIndex() == 0) { writeCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); WriteFont writeFont = new WriteFont(); writeFont.setItalic(true); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java index 8b984e6e..dc61c933 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java @@ -132,23 +132,22 @@ public class StyleDataTest { @Test public void t05AbstractVerticalCellStyleStrategy03() { AbstractVerticalCellStyleStrategy verticalCellStyleStrategy = new SimpleVerticalCellStyleStrategy(); - EasyExcel.write(file04, StyleOtherData.class).registerWriteHandler(verticalCellStyleStrategy).sheet() + EasyExcel.write(file04, AnnotationStyleData.class).registerWriteHandler(verticalCellStyleStrategy).sheet() .doWrite(data1()); } @Test - public void t06longestMatchColumnWidthStyleStrategy() { - EasyExcel.write(file05, StyleData.class) - .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet("模板").doWrite(data()); + public void t06longestMatchColumnWidthStyleStrategy() { + EasyExcel.write(file05, StyleData.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) + .sheet("模板").doWrite(data()); } @Test public void t07loopMergeStrategy() { - LoopMergeProperty loopMergeProperty = new LoopMergeProperty(1,2); + LoopMergeProperty loopMergeProperty = new LoopMergeProperty(1, 2); loopMergeProperty.setEachRow(2); loopMergeProperty.setColumnExtend(1); - EasyExcel.write(file06, LoopMergeData.class) - .registerWriteHandler(new LoopMergeStrategy(loopMergeProperty, 1)) + EasyExcel.write(file06, LoopMergeData.class).registerWriteHandler(new LoopMergeStrategy(loopMergeProperty, 1)) .sheet("模板").doWrite(data2()); } @@ -157,9 +156,10 @@ public class StyleDataTest { OnceAbsoluteMerge onceAbsoluteMerge = OnceAbsoluteMergeData.class.getAnnotation(OnceAbsoluteMerge.class); OnceAbsoluteMergeProperty onceAbsoluteMergeProperty = OnceAbsoluteMergeProperty.build(onceAbsoluteMerge); OnceAbsoluteMergeStrategy onceAbsoluteMergeStrategy = new OnceAbsoluteMergeStrategy(onceAbsoluteMergeProperty); - EasyExcel.write(file08, OnceAbsoluteMergeData.class) - .registerWriteHandler(onceAbsoluteMergeStrategy).sheet("模板").doWrite(data3()); + EasyExcel.write(file08, OnceAbsoluteMergeData.class).registerWriteHandler(onceAbsoluteMergeStrategy).sheet("模板") + .doWrite(data3()); } + private void readAndWrite(File file) { SimpleColumnWidthStyleStrategy simpleColumnWidthStyleStrategy = new SimpleColumnWidthStyleStrategy(50); SimpleRowHeightStyleStrategy simpleRowHeightStyleStrategy = @@ -199,12 +199,12 @@ public class StyleDataTest { return list; } - private List data1() { - List list = new ArrayList(); - StyleOtherData data = new StyleOtherData(); + private List data1() { + List list = new ArrayList(); + AnnotationStyleData data = new AnnotationStyleData(); data.setString("字符串0"); data.setString1("字符串01"); - StyleOtherData data1 = new StyleOtherData(); + AnnotationStyleData data1 = new AnnotationStyleData(); data1.setString("字符串1"); data1.setString1("字符串11"); list.add(data); @@ -218,7 +218,7 @@ public class StyleDataTest { LoopMergeData loopMergeData = new LoopMergeData(); loopMergeData.setCategory("洗漱用品"); loopMergeData.setTowel("毛巾"); - loopMergeData.setSize("10" + 1 + "#"); + loopMergeData.setSize("10" + i + "#"); list.add(loopMergeData); } return list; @@ -230,7 +230,7 @@ public class StyleDataTest { OnceAbsoluteMergeData onceAbsoluteMergeData = new OnceAbsoluteMergeData(); onceAbsoluteMergeData.setCategory("洗漱用品"); onceAbsoluteMergeData.setTowel("毛巾"); - onceAbsoluteMergeData.setSize("10" + 1 + "#"); + onceAbsoluteMergeData.setSize("10" + i + "#"); list.add(onceAbsoluteMergeData); } return list;