1
votes

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)?

1
The problem is different from the waterfall chart problem. The stock chart is a XWPFChart of supported type. But it's chart data is of type org.openxmlformats.schemas.drawingml.x2006.chart.CTStockChart which is not yet supported by XDDF. It only is supported using the low level ooxml-schemas classes. So no way around using those classes for changing the XML of org.openxmlformats.schemas.drawingml.x2006.chart.CTChart. But since you have XWPFChart, the method getWorkbook should give you the XSSFWorkbook to change the data source. But of course both is necessary.Axel Richter
Hi Axel, I was already updating the XML like you described for the Waterfall Chart, but indeed via accessing the CTChart class is way better. Thanks again! If you make your comment an answer then I can mark it as solved!Ivo Sturm

1 Answers

0
votes

The comment by Axel worked, with accessing the CTChart Class and manipulating it I was able to change the Stock Chart with the Apache POI library to my liking!