bug 60601: unlink hyperlinks from a sheet if all hyperlinks have been removed. Patch from Joachim Piketz

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1779426 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2017-01-19 07:44:25 +00:00
parent c0986ebe7a
commit 70cc2bce03
2 changed files with 26 additions and 0 deletions

View File

@ -3484,6 +3484,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
}
worksheet.getHyperlinks().setHyperlinkArray(ctHls);
}
else {
worksheet.unsetHyperlinks();
}
int minCell=Integer.MAX_VALUE, maxCell=Integer.MIN_VALUE;
for(XSSFRow row : _rows.values()){

View File

@ -1231,6 +1231,29 @@ public abstract class BaseTestSheet {
workbook.close();
}
@Test
public void removeAllHyperlinks() throws IOException {
Workbook workbook = _testDataProvider.createWorkbook();
Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(HyperlinkType.URL);
hyperlink.setAddress("https://poi.apache.org/");
Sheet sheet = workbook.createSheet();
Cell cell = sheet.createRow(5).createCell(1);
cell.setHyperlink(hyperlink);
assertEquals(1, workbook.getSheetAt(0).getHyperlinkList().size());
// Save a workbook with a hyperlink
Workbook workbook2 = _testDataProvider.writeOutAndReadBack(workbook);
assertEquals(1, workbook2.getSheetAt(0).getHyperlinkList().size());
// Remove all hyperlinks from a saved workbook
workbook2.getSheetAt(0).getRow(5).getCell(1).removeHyperlink();
assertEquals(0, workbook2.getSheetAt(0).getHyperlinkList().size());
// Verify that hyperlink was removed from workbook after writing out
Workbook workbook3 = _testDataProvider.writeOutAndReadBack(workbook2);
assertEquals(0, workbook3.getSheetAt(0).getHyperlinkList().size());
}
@Test