PDGGK opened a new pull request, #1564:
URL: https://github.com/apache/poi/pull/1564

   Fixes #1002
   
   Adding a chart to an existing presentation fails on `write()` with 
`PartAlreadyExistsException` when the deck already has an embedded workbook 
whose name the new chart wants to use. In #1002 that happens with a deck that 
holds two embedded Excel spreadsheets.
   
   `XMLSlideShow.createChart()` picks the chart index from the unused chart 
part names, and `XDDFChart.createWorksheetPart` then names the chart's workbook 
after that same index, `/ppt/embeddings/Microsoft_Excel_Worksheet<index>.xlsx`. 
The workbook name itself is never checked. A deck with 
`Microsoft_Excel_Worksheet.xlsx` and `Microsoft_Excel_Worksheet1.xlsx` and no 
charts gets chart index 1, so the workbook part clashes. PowerPoint uses these 
names for embedded workbooks: in `test-data/slideshow`, `chart-picture-bg.pptx` 
has `Microsoft_Excel_Worksheet.xlsx` and `bar-chart.pptx` has 
`Microsoft_Excel_Worksheet1.xlsx`.
   
   `createWorksheetPart` now asks `getNextPartNumber(chartWorkbookRelation, 
chartIndex)` for the workbook index, so the workbook keeps the chart index when 
that name is free and takes the next free number otherwise. `XWPFChart` goes 
through the same method.
   
   To reproduce it, I wrote a deck whose slide relates to two embedded 
workbooks named as above, then opened it with `XMLSlideShow`, added a pie chart 
with `createChart(slide)` and `plot()`, and saved it. With jars built from 
trunk, and with the 5.5.1 release, `write()` throws 
`PartAlreadyExistsException: A part with the name 
'/ppt/embeddings/Microsoft_Excel_Worksheet1.xlsx' already exists`. With the fix 
the deck is saved, and the chart's workbook is 
`Microsoft_Excel_Worksheet2.xlsx`.
   
   `TestXSLFChart.testGitHub1002` builds such a deck in memory, adds a chart, 
writes and reads it back, and checks both the chart data and the untouched 
embedded workbook. Without the change in `XDDFChart` it fails with the 
exception above. With it, the tests in `org.apache.poi.xslf.*`, 
`org.apache.poi.xddf.*` and `TestXWPFChart` pass (309 passed, 2 skipped), as do 
`forbiddenApisMain`, `forbiddenApisTest` and `rat`.
   
   I did not open the saved deck in PowerPoint, and I did not test the XWPF 
case with a real document.
   


-- 
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]

Reply via email to