From bb2ad49a2fc6c74948f8bb92701807093b525586 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alain=20B=C3=A9arez?= Date: Sat, 7 Dec 2019 23:39:20 +0000 Subject: [PATCH] Retrieve chart from graphical frame git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1871012 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xslf/usermodel/ChartFromScratch.java | 15 +++++++ .../poi/xslf/usermodel/XSLFGraphicFrame.java | 39 +++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java b/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java index 637b485bda..c4c0c23a95 100644 --- a/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java +++ b/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java @@ -21,6 +21,7 @@ package org.apache.poi.xslf.usermodel; import java.awt.geom.Rectangle2D; import java.io.BufferedReader; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.OutputStream; @@ -95,6 +96,20 @@ public class ChartFromScratch { ppt.write(out); } } + try (FileInputStream is = new FileInputStream("chart-from-scratch.pptx")) { + try (XMLSlideShow ppt = new XMLSlideShow(is)) { + for (XSLFSlide slide : ppt.getSlides()) { + for (XSLFShape shape : slide.getShapes()) { + if (shape instanceof XSLFGraphicFrame) { + XSLFGraphicFrame frame = (XSLFGraphicFrame) shape; + if (frame.hasChart()) { + System.out.println(frame.getChart().getTitleShape().getText()); + } + } + } + } + } + } } System.out.println("Done"); } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java index 8b9d152848..9ae6c9f956 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java @@ -47,6 +47,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape; @Beta public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame { + private static final String DRAWINGML_CHART_URI = "http://schemas.openxmlformats.org/drawingml/2006/chart"; private static final POILogger LOG = POILogFactory.getLogger(XSLFGraphicFrame.class); /*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){ @@ -97,7 +98,7 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame