We're pleased to announce the release of Spire.Office for Java 11.4.0. In this version, the Spire.Doc for Java supports saving charts as templates and retrieving data values from charts. Spire.PDF for Java optimizes memory consumption when merging PDFs. In addition, many known issues that occurred during the conversion and processing of Word/Excel/PDF/PowerPoint files have been successfully fixed. More details are listed below.
Click the link to download Spire.Office for Java 11.4.0:
Document doc = new Document();
doc.loadFromFile(inputFile);
int count = 1;
for (Section sec : (Iterable) doc.getSections()) {
for (Paragraph paragraph : (Iterable) sec.getParagraphs()) {
for (int i = 0; i < paragraph.getChildObjects().getCount(); i++) {
DocumentObject obj = paragraph.getChildObjects().get(i);
if (obj instanceof ShapeObject) {
ShapeObject shape = (ShapeObject) obj;
Chart chart = shape.getChart();
String fileName = outputFile + count + ".crtx";
chart.saveAsTemplate(fileName);
count++;
}
}
}
}
New Feature
SPIREDOC-10828
Adds the XValues property to retrieve data XValues on the chart's X-axis, and the YValues property to retrieve data values on the Y-axis for a specified series.
Document doc = new Document();
doc.loadFromFile(inputFile);
StringBuilder sb = new StringBuilder();
int pageNumber = 1;
for (Section sec : (Iterable) doc.getSections()) {
for (Paragraph paragraph : (Iterable) sec.getParagraphs()) {
for (int i = 0; i < paragraph.getChildObjects().getCount(); i++) {
DocumentObject obj = paragraph.getChildObjects().get(i);
if (obj instanceof ShapeObject) {
ShapeObject shape = (ShapeObject) obj;
Chart chart = shape.getChart();
sb.append("\r\n\r\nPage " + pageNumber + ":\r\n" + "All X-axis data: ");
for(int x = 0; x < chart.getXValues().getCount(); x++){
// Print all X-axis data values
ChartValue xVal = chart.getXValues().get(x);
sb.append(xVal.getStringValue() + " ");
}
ChartSeries series = chart.getSeries().get(0);
sb.append("\r\nY-axis data: ");
// Print all Y-axis data values of the first series
for(ChartValue yVal : (Iterable<ChartValue>)series.getYValues()){
sb.append(yVal.getValue() + " ");
}
}
}
}
pageNumber++;
}
New Feature
SPIREDOC-11457
Supports getting and setting the position of chart data labels.