I am using the Apache POI Java library (v4.1.1) to create wonderfull Word documents including Excel Charts. For the Excel Charts I use an Excel template and via the Apache POI library access the charts in the Word document via
List<XWPFChart> chartList = wordDoc.getCharts();
This is working fine for Bar / Column / Line etc. I can't get, however, the Stock chart to work, since when I want to access the XDDFChartData via
XDDFChartData chartData = xWPFChart.getChartSeries().get(0);
I get an IndexOutOfBoundException, hence the Apache POI library can't extract the XDDFChartData object from XWPFCHart. I looked into the release documents of the Apache POI library and I think the Stock Chart is not yet supported. What would be the best approach to update the Stock Chart?
Only try to update the Excel workbook data? Or is also an update of the XML needed, like described in the answer for the Waterfall chart (Updating Waterfall Chart with Apache POI)?
XWPFChart
of supported type. But it's chart data is of typeorg.openxmlformats.schemas.drawingml.x2006.chart.CTStockChart
which is not yet supported byXDDF
. It only is supported using the low levelooxml-schemas
classes. So no way around using those classes for changing theXML
oforg.openxmlformats.schemas.drawingml.x2006.chart.CTChart
. But since you haveXWPFChart
, the methodgetWorkbook
should give you theXSSFWorkbook
to change the data source. But of course both is necessary. – Axel Richter