Problem create chart from scratch with Apache Poi

333 Views Asked by At

When I create a chart from scratch and add it to a slide within a PowerPoint using Apache Poi the corresponding XSLFGraphicFrame shape get created and added to the XML but it doesn't get added to the getShapes() list within the slide, things that happen correctly for the other shapes type, is there any way to ascend the dependency tree up to the GraphicalFrame and get the corresponding XSLFShape object and add it by hand?

Example: Assume I have an XMLSlideShow object that we call ppt, ppt has an XSLFSLide object representing its slide in first position. So now this slide has some shapes. let's say these are 2 XSLFTextBox, that we can iterate over using method getShapes().

So if we create a chart from scratch:

//ppt.getSlides().get(0).getShapes().foreach .... sysout of each shapes produce something like shape1, shape2 we assumed before
XSLFChart chart = ppt.createChart(ppt.getSlides().get(0); //so adding the relation part to the first slide of our ppt
ppt.getSlides().get(0).addChart(chart, anchor); // we add the chart to the slide at some anchor we r interesting at
//now here do all things you need to populate your chart with data
//now ppt.getSlides().get(0).getShapes(). foreach .... sysout of this still produce shape1, shape2 and exclude shape3 (the actual just created chart)

But if we loop over XML objects bean we can actually find the graphical frame object that seems to not be added to the getShapes list.

How can I manually do this by first getting the corresponding shape?

EDIT: I managed to resolve the problem with a work-around since is too much work to edit the source code and rebuild the lib with ant+gradle etc etc. The ppt can be loaded from a stream, which is done by reading the xml file, which correctly lists the graphic frame. I wrote the ppt in a ByteArrayOutputStream and reload it from an input stream over the byte array; this fixed the problem.

0

There are 0 best solutions below