Example usage for org.apache.poi.xssf.usermodel XSSFRelation NS_CHART

List of usage examples for org.apache.poi.xssf.usermodel XSSFRelation NS_CHART

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFRelation NS_CHART.

Prototype

String NS_CHART

To view the source code for org.apache.poi.xssf.usermodel XSSFRelation NS_CHART.

Click Source Link

Usage

From source file:com.hp.autonomy.frontend.reports.powerpoint.SlideShowTemplate.java

License:MIT License

/**
 * Given an existing slide, search its relations to find a chart object.
 * @param slide a slide from the template.
 * @param error if we can't find a slide, this error message will be returned as the exception.
 * @return a pair containing the chart.xml data and the graphical object which represented it on the slide.
 * @throws TemplateLoadException if we can't find a chart object.
 *//* ww w  .j a v  a2s . c  om*/
private ImmutablePair<XSLFChart, CTGraphicalObjectFrame> getChart(final XSLFSlide slide, final String error)
        throws TemplateLoadException {
    for (POIXMLDocumentPart.RelationPart part : slide.getRelationParts()) {
        if (part.getDocumentPart() instanceof XSLFChart) {
            final String relId = part.getRelationship().getId();

            for (XSLFShape shape : slide.getShapes()) {
                if (shape instanceof XSLFGraphicFrame) {
                    final CTGraphicalObjectFrame frameXML = (CTGraphicalObjectFrame) shape.getXmlObject();
                    final XmlObject[] children = frameXML.getGraphic().getGraphicData()
                            .selectChildren(new QName(XSSFRelation.NS_CHART, "chart"));

                    for (final XmlObject child : children) {
                        final String imageRel = child.getDomNode().getAttributes()
                                .getNamedItemNS(RELATION_NAMESPACE, "id").getNodeValue();

                        if (relId.equals(imageRel)) {
                            return new ImmutablePair<>(part.getDocumentPart(), frameXML);
                        }
                    }
                }
            }
        }
    }

    throw new TemplateLoadException(error);
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.SlideShowTemplate.java

License:MIT License

/**
 * Utility function to clone the graphical object which represents a chart on a slide.
 * @param base the object to clone./*from w w  w  .  j  a  v a 2s.  c  o  m*/
 * @param relId the new relation ID we should insert.
 * @param shapeId the new shape ID we should insert.
 * @param shapeName the new shape name we should insert.
 * @param anchor the bounds of the new shape object in PowerPoint coordinates, if set, or null to use the existing clone's bounds.
 * @return a new clone object with the desired properties.
 */
private CTGraphicalObjectFrame cloneShapeXML(final CTGraphicalObjectFrame base, final String relId,
        final int shapeId, final String shapeName, final Rectangle2D.Double anchor) {
    /* Based on viewing the raw chart.
      <p:graphicFrame>
    <p:nvGraphicFramePr>
      <p:cNvPr id="4" name="Chart 3"/>
      <p:cNvGraphicFramePr/>
      <p:nvPr>
        <p:extLst>
          <p:ext uri="{D42A27DB-BD31-4B8C-83A1-F6EECF244321}">
            <p14:modId xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="866141002"/>
          </p:ext>
        </p:extLst>
      </p:nvPr>
    </p:nvGraphicFramePr>
    <p:xfrm>
      <a:off x="0" y="0"/>
      <a:ext cx="12192000" cy="6858000"/>
    </p:xfrm>
    <a:graphic>
      <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart">
        <c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
                 xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId2"/>
      </a:graphicData>
    </a:graphic>
      </p:graphicFrame>
     */
    final CTGraphicalObjectFrame copy = (CTGraphicalObjectFrame) base.copy();

    final CTNonVisualDrawingProps cNvPr = copy.getNvGraphicFramePr().getCNvPr();
    cNvPr.setName(shapeName);
    cNvPr.setId(shapeId);

    final XmlObject[] children = copy.getGraphic().getGraphicData()
            .selectChildren(new QName(XSSFRelation.NS_CHART, "chart"));

    if (anchor != null) {
        final CTPoint2D off = copy.getXfrm().getOff();
        off.setX((int) (anchor.getX() * EMU_PER_POINT));
        off.setY((int) (anchor.getY() * EMU_PER_POINT));

        final CTPositiveSize2D ext = copy.getXfrm().getExt();
        ext.setCx((int) (anchor.getWidth() * EMU_PER_POINT));
        ext.setCy((int) (anchor.getHeight() * EMU_PER_POINT));
    }

    for (final XmlObject child : children) {
        child.getDomNode().getAttributes().getNamedItemNS(RELATION_NAMESPACE, "id").setNodeValue(relId);
    }

    return copy;
}