How do we create a chart in a ppt in java using apache poi. Which POI API do we use. Below is code I am using to create a text box
XSLFSlide slide = pptx.createSlide();
XSLFTextShape textShape = slide.createTextBox();
textShape.setText(data);
The slide object doesnt contain any api for creating a chart.
Any solution to this?
Thanks in advance
There is nothing like a
XSLFChartShape
usable in a powerpoint slide inapache poi
until now.But of course if one knows the internal structure of the
*.pptx
ZIP
archive and theXML
therein, then it is possible creating this from scratch using theapache poi
OPCPackage
classes and the low levelCT*
classes fromorg.openxmlformats.schemas.drawingml.x2006.*
andorg.openxmlformats.schemas.presentationml.x2006.*
.Following code is doing this and creates a slide having a pie chart and a bar chart.
This is a draft only to show the approach.
Code which is producing the same but having
XSSFWorkbook
s as data tables.Edit January 29 2019:
Above code was working using
apache poi 3.16
up toapache poi 3.17
. To make it work using currentapache poi 4.0.1
the only need is changing theimport
s a little bit:This is because the Office Open XML stuff now is in
org.apache.poi.ooxml.*
and not more inorg.apache.poi.*
.