mirror of https://github.com/apache/poi.git
Fix for bug 46445 - move hyperlinks when shifting rows
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@730076 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2c65a65451
commit
70847d620e
|
@ -1187,6 +1187,12 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||||
cellRecord.setRow( rowNum + n );
|
cellRecord.setRow( rowNum + n );
|
||||||
row2Replace.createCellFromRecord( cellRecord );
|
row2Replace.createCellFromRecord( cellRecord );
|
||||||
sheet.addValueRecord( rowNum + n, cellRecord );
|
sheet.addValueRecord( rowNum + n, cellRecord );
|
||||||
|
|
||||||
|
HSSFHyperlink link = cell.getHyperlink();
|
||||||
|
if(link != null){
|
||||||
|
link.setFirstRow(link.getFirstRow() + n);
|
||||||
|
link.setLastRow(link.getLastRow() + n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Now zap all the cells in the source row
|
// Now zap all the cells in the source row
|
||||||
row.removeAllCells();
|
row.removeAllCells();
|
||||||
|
|
Binary file not shown.
|
@ -1642,4 +1642,28 @@ public final class TestBugs extends TestCase {
|
||||||
assertEquals("\u0161\u017E\u010D\u0148\u0159", sheet.getRow(1).getCell(0).getStringCellValue());
|
assertEquals("\u0161\u017E\u010D\u0148\u0159", sheet.getRow(1).getCell(0).getStringCellValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiple calls of HSSFWorkbook.write result in corrupted xls
|
||||||
|
*/
|
||||||
|
public void test32191() throws IOException {
|
||||||
|
HSSFWorkbook wb = openSample("27394.xls");
|
||||||
|
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
wb.write(out);
|
||||||
|
out.close();
|
||||||
|
int size1 = out.size();
|
||||||
|
|
||||||
|
out = new ByteArrayOutputStream();
|
||||||
|
wb.write(out);
|
||||||
|
out.close();
|
||||||
|
int size2 = out.size();
|
||||||
|
|
||||||
|
assertEquals(size1, size2);
|
||||||
|
out = new ByteArrayOutputStream();
|
||||||
|
wb.write(out);
|
||||||
|
out.close();
|
||||||
|
int size3 = out.size();
|
||||||
|
assertEquals(size2, size3);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,4 +184,49 @@ public final class TestHSSFHyperlink extends TestCase {
|
||||||
assertNotNull(link);
|
assertNotNull(link);
|
||||||
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
|
assertEquals("http://poi.apache.org/hssf/", link.getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that HSSFSheet#shiftRows moves hyperlinks,
|
||||||
|
* see bugs #46445 and #29957
|
||||||
|
*/
|
||||||
|
public void testShiftRows(){
|
||||||
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("46445.xls");
|
||||||
|
|
||||||
|
|
||||||
|
HSSFSheet sheet = wb.getSheetAt(0);
|
||||||
|
|
||||||
|
//verify existing hyperlink in A3
|
||||||
|
HSSFCell cell1 = sheet.getRow(2).getCell(0);
|
||||||
|
HSSFHyperlink link1 = cell1.getHyperlink();
|
||||||
|
assertNotNull(link1);
|
||||||
|
assertEquals(2, link1.getFirstRow());
|
||||||
|
assertEquals(2, link1.getLastRow());
|
||||||
|
|
||||||
|
//assign a hyperlink to A4
|
||||||
|
HSSFHyperlink link2 = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
|
||||||
|
link2.setAddress("Sheet2!A2");
|
||||||
|
HSSFCell cell2 = sheet.getRow(3).getCell(0);
|
||||||
|
cell2.setHyperlink(link2);
|
||||||
|
assertEquals(3, link2.getFirstRow());
|
||||||
|
assertEquals(3, link2.getLastRow());
|
||||||
|
|
||||||
|
//move the 3rd row two rows down
|
||||||
|
sheet.shiftRows(sheet.getFirstRowNum(), sheet.getLastRowNum(), 2);
|
||||||
|
|
||||||
|
//cells A3 and A4 don't contain hyperlinks anymore
|
||||||
|
assertNull(sheet.getRow(2).getCell(0).getHyperlink());
|
||||||
|
assertNull(sheet.getRow(3).getCell(0).getHyperlink());
|
||||||
|
|
||||||
|
//the first hypelink now belongs to A5
|
||||||
|
HSSFHyperlink link1_shifted = sheet.getRow(2+2).getCell(0).getHyperlink();
|
||||||
|
assertNotNull(link1_shifted);
|
||||||
|
assertEquals(4, link1_shifted.getFirstRow());
|
||||||
|
assertEquals(4, link1_shifted.getLastRow());
|
||||||
|
|
||||||
|
//the second hypelink now belongs to A6
|
||||||
|
HSSFHyperlink link2_shifted = sheet.getRow(3+2).getCell(0).getHyperlink();
|
||||||
|
assertNotNull(link2_shifted);
|
||||||
|
assertEquals(5, link2_shifted.getFirstRow());
|
||||||
|
assertEquals(5, link2_shifted.getLastRow());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue