/** * 创建对比分析图 */ private void createImageChartSlide( PresentationMLPackage presentationMLPackage) { String partTitle = ""; String partName = "/ppt/slides/" + getRandomID() + ".xml"; SlidePart slidePart = createCommonSlide(presentationMLPackage, partTitle, partName); try { // 读取本地文件获取Image部分代码略....... byte[] image; createImage(presentationMLPackage, slidePart, image, getRandomID(), partTitle, 611560, 1916831, 7992888, 3905767); } catch (IOException e) { e.printStackTrace(); } } /** * @param presentationMLPackage * @param slidePart * @param data * @param name * @param x * @param y * @param cx * @param cy */ private void createImage(PresentationMLPackage presentationMLPackage, SlidePart slidePart, byte[] data, String id, String name, long x, long y, long cx, long cy) { BinaryPartAbstractImage imagePart = null; try { imagePart = BinaryPartAbstractImage.createImagePart( presentationMLPackage, slidePart, data); } catch (Exception e) { e.printStackTrace(); } if (imagePart == null) return; HashMap mappings = new HashMap(); mappings.put("id1", id); mappings.put("name", ""); mappings.put("descr", ""); mappings.put("rEmbedId", imagePart.getSourceRelationship().getId()); // 注意,下面是图片位置的坐标 mappings.put("offx", Long.toString(x)); mappings.put("offy", Long.toString(y)); mappings.put("extcx", Long.toString(cx)); mappings.put("extcy", Long.toString(cy)); Object o; try { o = XmlUtils.unmarshallFromTemplate(imageXml, mappings, Context.jcPML, Pic.class); ((Sld) slidePart.getJaxbElement()).getCSld().getSpTree() .getSpOrGrpSpOrGraphicFrame().add(o); } catch (JAXBException e) { e.printStackTrace(); } } /** * 图片XML */ private final String imageXml = "<p:pic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" " + "xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" " + "xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\">" + "<p:nvPicPr><p:cNvPr id=\"${id1}\" name=\"${name}\" descr=\"${descr}\"/>" + "<p:cNvPicPr><a:picLocks noChangeAspect=\"1\"/></p:cNvPicPr><p:nvPr/></p:nvPicPr>" + "<p:blipFill><a:blip r:embed=\"${rEmbedId}\" cstate=\"print\"/><a:stretch><a:fillRect/>" + "</a:stretch></p:blipFill><p:spPr><a:xfrm><a:off x=\"${offx}\" y=\"${offy}\"/>" + "<a:ext cx=\"${extcx}\" cy=\"${extcy}\"/></a:xfrm><a:prstGeom prst=\"rect\"><a:avLst/>" + "</a:prstGeom></p:spPr></p:pic>"; |