From 908fe73545901cd3180e0f15701b3a623adb9eb8 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Wed, 6 Apr 2022 16:02:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A1=AB=E5=85=85=E6=A1=88?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fill/annotation/FillAnnotationData.java | 3 ++ .../annotation/FillAnnotationDataTest.java | 31 ++++++++++++++++++ .../alibaba/easyexcel/test/temp/LockTest.java | 2 +- .../src/test/resources/fill/annotation.xls | Bin 26624 -> 27136 bytes .../src/test/resources/fill/annotation.xlsx | Bin 10692 -> 10742 bytes 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationData.java b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationData.java index bc4c2483..87e2bfae 100644 --- a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationData.java +++ b/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.write.style.ContentLoopMerge; import com.alibaba.excel.annotation.write.style.ContentRowHeight; +import com.alibaba.excel.converters.string.StringImageConverter; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -33,4 +34,6 @@ public class FillAnnotationData { private String string1; @ExcelProperty("字符串2") private String string2; + @ExcelProperty(value = "图片", converter = StringImageConverter.class) + private String image; } diff --git a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java index 93680d69..d2159e71 100644 --- a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java +++ b/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.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.PictureData; 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.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.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; /** * @author Jiaju Zhuang @@ -73,6 +83,26 @@ public class FillAnnotationDataTest { } } Assert.assertTrue(hasMerge); + if (sheet instanceof XSSFSheet) { + XSSFSheet xssfSheet = (XSSFSheet)sheet; + List 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 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 data() throws Exception { @@ -82,6 +112,7 @@ public class FillAnnotationDataTest { data.setNumber(99.99); data.setString1("string1"); data.setString2("string2"); + data.setImage(TestFileUtil.getPath() + "converter" + File.separator + "img.jpg"); list.add(data); list.add(data); list.add(data); diff --git a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java index 322891da..07cb7989 100644 --- a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java +++ b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/LockTest.java @@ -24,7 +24,7 @@ public class LockTest { @Test public void test() throws Exception { List 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) { LOGGER.info("返回数据:{}", JSON.toJSONString(data)); } diff --git a/easyexcel-core/src/test/resources/fill/annotation.xls b/easyexcel-core/src/test/resources/fill/annotation.xls index 8fd19c5a7fa7300facc2a11f4f84c04ff6606b40..de09678c72f3ffdcb9a592432489129f66ec11bb 100644 GIT binary patch delta 2534 zcmchZYiv|S6vxlpz5D9!b|2kGw~yVmJoeRgx0DJ9+isy-Kod*lVSEroXptyJ3GxA~ zyAm+bN+>-DQ4loIL<-2`0;Wa<{h(>$hmw$JP@@=5 zqpB>Qz*Y4pg}-0pB`UodFQ)So;Xj$bqVi&TiW7#XnDEXN{PYz3oZ!WK;gHkmwRkE0 zZwO90>8f!6*4YAvc6fHhR=3h=bLsG;%Yh&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