public void testRead() throws IOException { XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithDrawing.xlsx"); XSSFSheet sheet = wb.getSheetAt(0); // the sheet has one relationship and it is XSSFDrawing List<POIXMLDocumentPart> rels = sheet.getRelations(); assertEquals(1, rels.size()); assertTrue(rels.get(0) instanceof XSSFDrawing); XSSFDrawing drawing = (XSSFDrawing) rels.get(0); // sheet.createDrawingPatriarch() should return the same instance of XSSFDrawing assertSame(drawing, sheet.createDrawingPatriarch()); String drawingId = drawing.getPackageRelationship().getId(); // there should be a relation to this drawing in the worksheet assertTrue(sheet.getCTWorksheet().isSetDrawing()); assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId()); List<XSSFShape> shapes = drawing.getShapes(); assertEquals(6, shapes.size()); assertTrue(shapes.get(0) instanceof XSSFPicture); assertTrue(shapes.get(1) instanceof XSSFPicture); assertTrue(shapes.get(2) instanceof XSSFPicture); assertTrue(shapes.get(3) instanceof XSSFPicture); assertTrue(shapes.get(4) instanceof XSSFSimpleShape); assertTrue(shapes.get(5) instanceof XSSFPicture); for (XSSFShape sh : shapes) assertNotNull(sh.getAnchor()); assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb)); }