https://bz.apache.org/bugzilla/show_bug.cgi?id=70138

            Bug ID: 70138
           Summary: When a chart is inserted into a previously existing
                    pptx file having two or more Excel spreadsheets saving
                    the pptx file fails.
           Product: POI
           Version: 5.5.1-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSLF
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

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. I
have a test case showing the bug at
https://github.com/jamdba/PoiChartBugExamples .

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to