Browse Source

Merge pull request #1863 from alibaba/revert-1323-styleOtherTest01

Revert "easyexcel整体覆盖率提升3%"
developing
Jiaju Zhuang 4 years ago committed by GitHub
parent
commit
a3f1707076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      easyexcel
  2. 21
      src/test/java/com/alibaba/easyexcel/test/core/style/AnnotationStyleData.java
  3. 17
      src/test/java/com/alibaba/easyexcel/test/core/style/LoopMergeData.java
  4. 19
      src/test/java/com/alibaba/easyexcel/test/core/style/OnceAbsoluteMergeData.java
  5. 52
      src/test/java/com/alibaba/easyexcel/test/core/style/SimpleVerticalCellStyleStrategy.java
  6. 80
      src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java

1
easyexcel

@ -1 +0,0 @@
Subproject commit 4076b897953b18f9e96c278c6929325e89f2be12

21
src/test/java/com/alibaba/easyexcel/test/core/style/AnnotationStyleData.java

@ -1,21 +0,0 @@
package com.alibaba.easyexcel.test.core.style;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ContentFontStyle;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import lombok.Data;
/**
* @author Pengliang Zhao
*/
@Data
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;
@ExcelProperty("字符串1")
private String string1;
}

17
src/test/java/com/alibaba/easyexcel/test/core/style/LoopMergeData.java

@ -1,17 +0,0 @@
package com.alibaba.easyexcel.test.core.style;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
/**
* @author Pengliang Zhao
*/
@Data
public class LoopMergeData {
@ExcelProperty(value = "洗漱种类", index = 0)
private String category;
@ExcelProperty(value = "毛巾名称", index = 1)
private String towel;
@ExcelProperty(value = "毛巾尺寸", index = 2)
private String size;
}

19
src/test/java/com/alibaba/easyexcel/test/core/style/OnceAbsoluteMergeData.java

@ -1,19 +0,0 @@
package com.alibaba.easyexcel.test.core.style;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.OnceAbsoluteMerge;
import lombok.Data;
/**
* @author Pengliang Zhao
*/
@Data
@OnceAbsoluteMerge(firstRowIndex = (short)0, lastRowIndex = (short)2, firstColumnIndex = (short)0, lastColumnIndex = (short)2)
public class OnceAbsoluteMergeData {
@ExcelProperty(value = "洗漱种类", index = 0)
private String category;
@ExcelProperty(value = "毛巾名称", index = 1)
private String towel;
@ExcelProperty(value = "毛巾尺寸", index = 2)
private String size;
}

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

@ -1,52 +0,0 @@
package com.alibaba.easyexcel.test.core.style;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import com.alibaba.excel.annotation.write.style.ContentFontStyle;
import com.alibaba.excel.annotation.write.style.ContentStyle;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.property.FontProperty;
import com.alibaba.excel.metadata.property.StyleProperty;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy;
/**
* @author Pengliang Zhao
*/
public class SimpleVerticalCellStyleStrategy extends AbstractVerticalCellStyleStrategy {
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) {
writeCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
WriteFont writeFont = new WriteFont();
writeFont.setItalic(true);
writeFont.setStrikeout(true);
writeFont.setTypeOffset(Font.SS_NONE);
writeFont.setUnderline(Font.U_DOUBLE);
writeFont.setBold(true);
writeFont.setCharset((int)Font.DEFAULT_CHARSET);
} else {
writeCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
}
return writeCellStyle;
}
@Override
protected WriteCellStyle contentCellStyle(Head head) {
WriteCellStyle writeCellStyle = new WriteCellStyle();
writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
if (head.getColumnIndex() == 0) {
writeCellStyle.setFillForegroundColor(IndexedColors.DARK_GREEN.getIndex());
} else {
writeCellStyle.setFillForegroundColor(IndexedColors.PINK.getIndex());
}
return writeCellStyle;
}
}

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

@ -17,17 +17,13 @@ import org.junit.runners.MethodSorters;
import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.write.style.OnceAbsoluteMerge;
import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.property.LoopMergeProperty;
import com.alibaba.excel.metadata.property.OnceAbsoluteMergeProperty;
import com.alibaba.excel.write.merge.LoopMergeStrategy; import com.alibaba.excel.write.merge.LoopMergeStrategy;
import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy; import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy;
import com.alibaba.excel.write.metadata.style.WriteCellStyle; import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont; import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy; import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy; import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy;
@ -40,19 +36,11 @@ public class StyleDataTest {
private static File file07; private static File file07;
private static File file03; private static File file03;
private static File file04;
private static File file05;
private static File file06;
private static File file08;
@BeforeClass @BeforeClass
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("style07.xlsx"); file07 = TestFileUtil.createNewFile("style07.xlsx");
file03 = TestFileUtil.createNewFile("style03.xls"); file03 = TestFileUtil.createNewFile("style03.xls");
file04 = TestFileUtil.createNewFile("simpleVerticalCellStyleStrategy01.xls");
file05 = TestFileUtil.createNewFile("longestMatchColumnWidthStyleStrategy01.xls");
file06 = TestFileUtil.createNewFile("loopMergeStrategy01.xls");
file08 = TestFileUtil.createNewFile("onceAbsoluteMergeStrategy01.xls");
} }
@Test @Test
@ -129,37 +117,6 @@ public class StyleDataTest {
.doWrite(data10()); .doWrite(data10());
} }
@Test
public void t05AbstractVerticalCellStyleStrategy03() {
AbstractVerticalCellStyleStrategy verticalCellStyleStrategy = new SimpleVerticalCellStyleStrategy();
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());
}
@Test
public void t07loopMergeStrategy() {
LoopMergeProperty loopMergeProperty = new LoopMergeProperty(1, 2);
loopMergeProperty.setEachRow(2);
loopMergeProperty.setColumnExtend(1);
EasyExcel.write(file06, LoopMergeData.class).registerWriteHandler(new LoopMergeStrategy(loopMergeProperty, 1))
.sheet("模板").doWrite(data2());
}
@Test
public void to8onceAbsoluteMergeStrategy() {
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());
}
private void readAndWrite(File file) { private void readAndWrite(File file) {
SimpleColumnWidthStyleStrategy simpleColumnWidthStyleStrategy = new SimpleColumnWidthStyleStrategy(50); SimpleColumnWidthStyleStrategy simpleColumnWidthStyleStrategy = new SimpleColumnWidthStyleStrategy(50);
SimpleRowHeightStyleStrategy simpleRowHeightStyleStrategy = SimpleRowHeightStyleStrategy simpleRowHeightStyleStrategy =
@ -199,43 +156,6 @@ public class StyleDataTest {
return list; return list;
} }
private List<AnnotationStyleData> data1() {
List<AnnotationStyleData> list = new ArrayList<AnnotationStyleData>();
AnnotationStyleData data = new AnnotationStyleData();
data.setString("字符串0");
data.setString1("字符串01");
AnnotationStyleData data1 = new AnnotationStyleData();
data1.setString("字符串1");
data1.setString1("字符串11");
list.add(data);
list.add(data1);
return list;
}
private List<LoopMergeData> data2() {
List<LoopMergeData> list = new ArrayList<LoopMergeData>();
for (int i = 0; i <= 5; i++) {
LoopMergeData loopMergeData = new LoopMergeData();
loopMergeData.setCategory("洗漱用品");
loopMergeData.setTowel("毛巾");
loopMergeData.setSize("10" + i + "#");
list.add(loopMergeData);
}
return list;
}
private List<OnceAbsoluteMergeData> data3() {
List<OnceAbsoluteMergeData> list = new ArrayList<OnceAbsoluteMergeData>();
for (int i = 0; i <= 5; i++) {
OnceAbsoluteMergeData onceAbsoluteMergeData = new OnceAbsoluteMergeData();
onceAbsoluteMergeData.setCategory("洗漱用品");
onceAbsoluteMergeData.setTowel("毛巾");
onceAbsoluteMergeData.setSize("10" + i + "#");
list.add(onceAbsoluteMergeData);
}
return list;
}
private List<StyleData> data10() { private List<StyleData> data10() {
List<StyleData> list = new ArrayList<StyleData>(); List<StyleData> list = new ArrayList<StyleData>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {

Loading…
Cancel
Save