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 8fd19c5a..de09678c 100644 Binary files a/easyexcel-core/src/test/resources/fill/annotation.xls and b/easyexcel-core/src/test/resources/fill/annotation.xls differ diff --git a/easyexcel-core/src/test/resources/fill/annotation.xlsx b/easyexcel-core/src/test/resources/fill/annotation.xlsx index 5395232b..2a4a92b6 100644 Binary files a/easyexcel-core/src/test/resources/fill/annotation.xlsx and b/easyexcel-core/src/test/resources/fill/annotation.xlsx differ