Browse Source

Improved the code

developing
dota17 5 years ago
parent
commit
8368d37338
  1. 7
      src/test/java/com/alibaba/easyexcel/test/core/style/AnnotationStyleData.java
  2. 4
      src/test/java/com/alibaba/easyexcel/test/core/style/SimpleVerticalCellStyleStrategy.java
  3. 26
      src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java

7
src/test/java/com/alibaba/easyexcel/test/core/style/StyleOtherData.java → 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;

4
src/test/java/com/alibaba/easyexcel/test/core/style/SimpleVerticalCellStyleStrategy.java

@ -17,8 +17,8 @@ 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) {

26
src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java

@ -132,14 +132,14 @@ 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());
EasyExcel.write(file05, StyleData.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.sheet("模板").doWrite(data());
}
@Test
@ -147,8 +147,7 @@ public class StyleDataTest {
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<StyleOtherData> data1() {
List<StyleOtherData> list = new ArrayList<StyleOtherData>();
StyleOtherData data = new StyleOtherData();
private List<AnnotationStyleData> data1() {
List<AnnotationStyleData> list = new ArrayList<AnnotationStyleData>();
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;

Loading…
Cancel
Save