use of org.docx4j.dml.chart.CTNumVal in project docx4j-template by vindell.
the class Docx4j_替换模板 method replacePieChartData.
/**
* 替换图表数据
*/
private void replacePieChartData(WordprocessingMLPackage wordMLPackage, String[] chartArr) throws Docx4JException {
RelationshipsPart rp = wordMLPackage.getMainDocumentPart().getRelationshipsPart();
Relationship rel = rp.getRelationshipByType(Namespaces.SPREADSHEETML_CHART);
Chart chart = (Chart) rp.getPart(rel);
CTChartSpace chartSpace = chart.getContents();
List<Object> charObjList = chartSpace.getChart().getPlotArea().getAreaChartOrArea3DChartOrLineChart();
CTPieChart pieChart = (CTPieChart) charObjList.get(0);
List<CTPieSer> serList = pieChart.getSer();
CTNumDataSource serVal = serList.get(0).getVal();
List<CTNumVal> ptList = serVal.getNumRef().getNumCache().getPt();
ptList.get(0).setV(chartArr[0]);
ptList.get(1).setV(chartArr[1]);
}
Aggregations