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

   A follow-up to the `cloneSheet` part of #1584, for hyperlinks that were 
added in memory rather than loaded.
   
   ```java
   XSSFWorkbook wb = new XSSFWorkbook();
   XSSFSheet sheet = wb.createSheet("src");
   XSSFHyperlink link = 
wb.getCreationHelper().createHyperlink(HyperlinkType.URL);
   link.setAddress("https://example.com/new";);
   sheet.createRow(0).createCell(0).setHyperlink(link);
   wb.cloneSheet(0, "clone");
   // IllegalStateException: The hyperlink for cell A1 references relation 
rId1, but that didn't exist!
   ```
   
   A hyperlink added to a sheet gets its relationship only when the sheet is 
written (`generateRelationIfNeeded` in `XSSFSheet.write`). `cloneSheet` copies 
the source sheet's relationships first and then writes the sheet to read it 
into the clone, so the written `r:id` has no relationship on the clone. 
`cloneSheet` now generates the relationships of the source sheet's hyperlinks 
before copying them. Writing the source sheet later doesn't add a second one, 
because the hyperlink then already holds its relationship.
   
   **Test:** `TestXSSFHyperlink.testCloneSheetWithNewHyperlink`: a URL and an 
internal hyperlink, cloned without writing first. It checks both sheets before 
and after writing and reading back, and that each has exactly one hyperlink 
relationship. It fails on trunk with the exception above. All 2357 
`org.apache.poi.xssf` tests pass.
   


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