Browse Source

新增填充案例

pull/2317/merge
Jiaju Zhuang 3 years ago
parent
commit
908fe73545
  1. 3
      easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationData.java
  2. 31
      easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java
  3. 2
      easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java
  4. BIN
      easyexcel-core/src/test/resources/fill/annotation.xls
  5. BIN
      easyexcel-core/src/test/resources/fill/annotation.xlsx

3
easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationData.java

@ -7,6 +7,7 @@ import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.format.NumberFormat; import com.alibaba.excel.annotation.format.NumberFormat;
import com.alibaba.excel.annotation.write.style.ContentLoopMerge; import com.alibaba.excel.annotation.write.style.ContentLoopMerge;
import com.alibaba.excel.annotation.write.style.ContentRowHeight; import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.converters.string.StringImageConverter;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
@ -33,4 +34,6 @@ public class FillAnnotationData {
private String string1; private String string1;
@ExcelProperty("字符串2") @ExcelProperty("字符串2")
private String string2; private String string2;
@ExcelProperty(value = "图片", converter = StringImageConverter.class)
private String image;
} }

31
easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java

@ -9,17 +9,27 @@ import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.DateUtils;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPicture;
import org.apache.poi.hssf.usermodel.HSSFShape;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFAnchor;
import org.apache.poi.xssf.usermodel.XSSFPicture;
import org.apache.poi.xssf.usermodel.XSSFShape;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test; import org.junit.Test;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
/** /**
* @author Jiaju Zhuang * @author Jiaju Zhuang
@ -73,6 +83,26 @@ public class FillAnnotationDataTest {
} }
} }
Assert.assertTrue(hasMerge); Assert.assertTrue(hasMerge);
if (sheet instanceof XSSFSheet) {
XSSFSheet xssfSheet = (XSSFSheet)sheet;
List<XSSFShape> shapeList = xssfSheet.getDrawingPatriarch().getShapes();
XSSFShape shape0 = shapeList.get(0);
Assert.assertTrue(shape0 instanceof XSSFPicture);
XSSFPicture picture0 = (XSSFPicture)shape0;
CTMarker ctMarker0 = picture0.getPreferredSize().getFrom();
Assert.assertEquals(1, ctMarker0.getRow());
Assert.assertEquals(4, ctMarker0.getCol());
} else {
HSSFSheet hssfSheet = (HSSFSheet)sheet;
List<HSSFShape> shapeList = hssfSheet.getDrawingPatriarch().getChildren();
HSSFShape shape0 = shapeList.get(0);
Assert.assertTrue(shape0 instanceof HSSFPicture);
HSSFPicture picture0 = (HSSFPicture)shape0;
HSSFClientAnchor anchor = (HSSFClientAnchor)picture0.getAnchor();
Assert.assertEquals(1, anchor.getRow1());
Assert.assertEquals(4, anchor.getCol1());
}
} }
private List<FillAnnotationData> data() throws Exception { private List<FillAnnotationData> data() throws Exception {
@ -82,6 +112,7 @@ public class FillAnnotationDataTest {
data.setNumber(99.99); data.setNumber(99.99);
data.setString1("string1"); data.setString1("string1");
data.setString2("string2"); data.setString2("string2");
data.setImage(TestFileUtil.getPath() + "converter" + File.separator + "img.jpg");
list.add(data); list.add(data);
list.add(data); list.add(data);
list.add(data); list.add(data);

2
easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java

@ -24,7 +24,7 @@ public class LockTest {
@Test @Test
public void test() throws Exception { public void test() throws Exception {
List<Object> list = List<Object> list =
EasyExcel.read(new FileInputStream("/Users/zhuangjiaju/Downloads/test.xlsx")).useDefaultListener(false).doReadAllSync(); EasyExcel.read(new FileInputStream("/Users/zhuangjiaju/Downloads/-0304.2.xlsx")).useDefaultListener(false).doReadAllSync();
for (Object data : list) { for (Object data : list) {
LOGGER.info("返回数据:{}", JSON.toJSONString(data)); LOGGER.info("返回数据:{}", JSON.toJSONString(data));
} }

BIN
easyexcel-core/src/test/resources/fill/annotation.xls

Binary file not shown.

BIN
easyexcel-core/src/test/resources/fill/annotation.xlsx

Binary file not shown.
Loading…
Cancel
Save