jamdba opened a new issue, #1002:
URL: https://github.com/apache/poi/issues/1002
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]