mirror of https://github.com/apache/poi.git
[bug-65973] fix for removing hyperlinks that span multiple cells
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899139 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
aff20dc6f9
commit
902d1487f7
|
@ -3085,8 +3085,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx
|
||||||
if (hyperlinks != null) {
|
if (hyperlinks != null) {
|
||||||
for (XSSFHyperlink link : new ArrayList<>(hyperlinks)) {
|
for (XSSFHyperlink link : new ArrayList<>(hyperlinks)) {
|
||||||
CellRangeAddress range = CellRangeAddress.valueOf(link.getCellRef());
|
CellRangeAddress range = CellRangeAddress.valueOf(link.getCellRef());
|
||||||
//TODO handle case where hyperlink ref spans many rows (https://bz.apache.org/bugzilla/show_bug.cgi?id=65973)
|
|
||||||
//but where only some rows are being removed and others are not (range will need to be modified)
|
|
||||||
if (range.getFirstRow() == range.getLastRow() && rowsToRemoveSet.contains(range.getFirstRow())) {
|
if (range.getFirstRow() == range.getLastRow() && rowsToRemoveSet.contains(range.getFirstRow())) {
|
||||||
removeHyperlink(link);
|
removeHyperlink(link);
|
||||||
} else if (range.getFirstRow() != range.getLastRow()) {
|
} else if (range.getFirstRow() != range.getLastRow()) {
|
||||||
|
|
|
@ -2325,6 +2325,29 @@ public final class TestXSSFSheet extends BaseTestXSheet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testRowShiftWithHyperlink3() throws IOException {
|
||||||
|
try (XSSFWorkbook wb = createWorkbookForRowShiftWithHyperlink1(false)) {
|
||||||
|
XSSFSheet sheet = wb.getSheetAt(0);
|
||||||
|
List<XSSFHyperlink> hyperlinks = sheet.getHyperlinkList();
|
||||||
|
assertEquals(1, hyperlinks.size());
|
||||||
|
assertEquals("B1:B2", hyperlinks.get(0).getCellRef());
|
||||||
|
assertEquals(3, sheet.getLastRowNum());
|
||||||
|
|
||||||
|
sheet.shiftRows(2, 3, -1);
|
||||||
|
assertEquals(2, sheet.getLastRowNum());
|
||||||
|
XSSFRow row0 = sheet.getRow(0);
|
||||||
|
XSSFRow row1 = sheet.getRow(1);
|
||||||
|
XSSFRow row2 = sheet.getRow(2);
|
||||||
|
assertEquals("row0", row0.getCell(0).getStringCellValue());
|
||||||
|
assertEquals("row2", row1.getCell(0).getStringCellValue());
|
||||||
|
assertEquals("row3", row2.getCell(0).getStringCellValue());
|
||||||
|
List<XSSFHyperlink> hyperlinks2 = sheet.getHyperlinkList();
|
||||||
|
assertEquals(1, hyperlinks2.size());
|
||||||
|
assertEquals("B1", hyperlinks2.get(0).getCellRef());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private XSSFWorkbook createWorkbookForRowShiftWithHyperlink1(boolean hyperlinkOneRow) {
|
private XSSFWorkbook createWorkbookForRowShiftWithHyperlink1(boolean hyperlinkOneRow) {
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = wb.createSheet("Sheet1");
|
XSSFSheet sheet = wb.createSheet("Sheet1");
|
||||||
|
|
Loading…
Reference in New Issue