I have a power point slide which has multiple charts (multiple bar and line chart) i need to update them using apache POI library. so far i used to have one chart per slide and i used to get the chart using below code to identify and update the values.
XSLFChart chart = null;
for(POIXMLDocumentPart part : mainSlide.getRelations()){
if(part instanceof XSLFChart){
chart = (XSLFChart) part;
break;
}
}
not sure how to identify specific chart dont see any method like i could identify like shape
for(XSLFSlide slide:ppt.getSlides()){
for (XSLFShape shape : slide.getShapes()) {
if (shapeName.equals(shape.getShapeName()))
return slide;
}
}
i gave name to table,textbox in powerpoint and can retrieve in code using shapename but dont see anything for chart . can any one help me plz?
i figured out a way to identify that with help of office mate.
first give a title to chart in power point open layout> chart title> above chart then give any name . to hide that title keep the font size small and make font color as white .
add code in java as below
private XSLFChart getChartObject(XSLFSlide mainSlide,String chartName) throws IOException
{
XSLFChart chart = null;
for(POIXMLDocumentPart part : mainSlide.getRelations()){
if(part instanceof XSLFChart){
chart = (XSLFChart) part;
if(chart.getCTChart().getTitle()!=null && chart.getCTChart().getTitle().getTx()!=null){
if(chart.getCTChart().getTitle().getTx().getRich().getPList().get(0).getRList().get(0).getT().equals(chartName))
break;
}
}
}
return chart;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.