}
}
private void putImage(WorksheetPart worksheetPart, SpreadsheetMLPackage pkg, BinaryPartAbstractImage xlsxImage, Image image, CTTwoCellAnchor anchor) throws InvalidFormatException {
PartName drawingPartName = new PartName(worksheetPart.getPartName().getName().replace("worksheets/sheet", "drawings/drawing"));
Drawing drawing = (Drawing) pkg.getParts().get(drawingPartName);
java.util.List<Object> objects = drawing.getJaxbElement().getEGAnchor();
String rid = "rId" + (objects.size() + 1);
CTPicture pic = new CTPicture();
CTPictureNonVisual nvPicPr = new CTPictureNonVisual();
CTNonVisualDrawingProps nvpr = new CTNonVisualDrawingProps();
nvpr.setId(objects.size() + 2);
String name = xlsxImage.getPartName().getName();
name = name.substring(name.lastIndexOf("/") + 1);
nvpr.setName(name);
nvpr.setDescr(name);
nvPicPr.setCNvPr(nvpr);
CTPictureLocking ctPictureLocking = new CTPictureLocking();
ctPictureLocking.setNoChangeAspect(true);
CTNonVisualPictureProperties nvpp = new CTNonVisualPictureProperties();
nvpp.setPicLocks(ctPictureLocking);
nvPicPr.setCNvPicPr(nvpp);
pic.setNvPicPr(nvPicPr);
CTBlipFillProperties blipProps = new CTBlipFillProperties();
CTStretchInfoProperties props = new CTStretchInfoProperties();
CTRelativeRect rect = new CTRelativeRect();
props.setFillRect(rect);
blipProps.setStretch(props);
CTBlip blip = new CTBlip();
blip.setEmbed(rid);
blip.setCstate(STBlipCompression.PRINT);
blipProps.setBlip(blip);
pic.setBlipFill(blipProps);
CTShapeProperties sppr = new CTShapeProperties();
ImageSize imageSize = new ImageSize(image.width, image.height, 96);//todo this doesn't work unfortunately
imageSize.calcSizeFromPixels();
CTPoint2D off = new CTPoint2D();
off.setX(0);
off.setY(0);
CTPositiveSize2D ext = new CTPositiveSize2D();
ext.setCx(imageSize.getWidthMpt());
ext.setCy(imageSize.getHeightMpt());
CTTransform2D xfrm = new CTTransform2D();
xfrm.setOff(off);
xfrm.setExt(ext);
sppr.setXfrm(xfrm);
CTPresetGeometry2D prstGeom = new CTPresetGeometry2D();
prstGeom.setPrst(STShapeType.RECT);
prstGeom.setAvLst(new CTGeomGuideList());
sppr.setPrstGeom(prstGeom);
pic.setSpPr(sppr);
anchor.setPic(pic);
CTAnchorClientData data = new CTAnchorClientData();
anchor.setClientData(data);
drawing.getJaxbElement().getEGAnchor().add(anchor);
Relationship rel = new Relationship();
rel.setId(rid);
rel.setType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image");
rel.setTarget("../media/" + name);
drawing.getRelationshipsPart().addRelationship(rel);
RelationshipsPart relPart = drawing.getRelationshipsPart();
pkg.getParts().remove(relPart.getPartName());
pkg.getParts().put(relPart);
pkg.getParts().remove(drawing.getPartName());
pkg.getParts().put(drawing);
}