-
Notifications
You must be signed in to change notification settings - Fork 817
Description
When a PowerPoint file that has two or more existing embedded Excel spreadsheets is opened and a chart is inserted saving the .pptx file fails with an org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException.
This is a result of XSLFChart (XDDFChart) storing it's data as an XSSFWorkbook. Although the chart index is considered in the XMLSlideShow.findNextAvailableFileNameIndex method (via XSLFRelation.CHART) the workbook index is not.
Workbook index state is not managed as closely as the chart indexes. It appears that they need to be known to the XMLSlideShow, as multiple charts on a pptx with multiple embedded Excel files will also fail.
Our temporary solution was to add an int workbookIndex property to the XDDFChart class, as well as a currentWorkbookIndex int property in the XMLSlideShow class, and manage them in the XMLSlideShow class:
public XSLFChart createChart() {
int chartIdx = findNextAvailableFileNameIndex(XSLFRelation.CHART);
int workbookIdx = findNextAvailableFileNameIndex(XSLFRelation.WORKBOOK);
XSLFChart chart = createRelationship(XSLFRelation.CHART, XSLFFactory.getInstance(), chartIdx, true).getDocumentPart();
chart.setChartIndex(chartIdx);
if (workbookIdx > currentWorkbookIndex ) {
this.currentWorkbookIndex = workbookIdx;
} else {
this.currentWorkbookIndex++;
}
chart.setWorkbookIndex(currentWorkbookIndex);
_charts.add(chart);
return chart;
}
Hopefully you guys knowing the model better can find a more elegant solution.
Thanks.