use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class TestXSSFHyperlink method testURLsWithHashMark.
/* bug 59775: XSSFHyperlink has wrong type if it contains a location (CTHyperlink#getLocation)
* URLs with a hash mark (#) are still URL hyperlinks, not document links
*/
@Test
public void testURLsWithHashMark() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("59775.xlsx");
XSSFSheet sh = wb.getSheetAt(0);
CellAddress A2 = new CellAddress("A2");
CellAddress A3 = new CellAddress("A3");
CellAddress A4 = new CellAddress("A4");
CellAddress A7 = new CellAddress("A7");
XSSFHyperlink link = sh.getHyperlink(A2);
assertEquals("address", "A2", link.getCellRef());
assertEquals("link type", HyperlinkType.URL, link.getTypeEnum());
assertEquals("link target", "http://twitter.com/#!/apacheorg", link.getAddress());
link = sh.getHyperlink(A3);
assertEquals("address", "A3", link.getCellRef());
assertEquals("link type", HyperlinkType.URL, link.getTypeEnum());
assertEquals("link target", "http://www.bailii.org/databases.html#ie", link.getAddress());
link = sh.getHyperlink(A4);
assertEquals("address", "A4", link.getCellRef());
assertEquals("link type", HyperlinkType.URL, link.getTypeEnum());
assertEquals("link target", "https://en.wikipedia.org/wiki/Apache_POI#See_also", link.getAddress());
link = sh.getHyperlink(A7);
assertEquals("address", "A7", link.getCellRef());
assertEquals("link type", HyperlinkType.DOCUMENT, link.getTypeEnum());
assertEquals("link target", "Sheet1", link.getAddress());
wb.close();
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class TestXSSFSheet method testRemoveRowWithCommentAndGapAbove.
// bug 59687: XSSFSheet.RemoveRow doesn't handle row gaps properly when removing row comments
@Test
public void testRemoveRowWithCommentAndGapAbove() throws IOException {
final Workbook wb = _testDataProvider.openSampleWorkbook("59687.xlsx");
final Sheet sheet = wb.getSheetAt(0);
// comment exists
CellAddress commentCellAddress = new CellAddress("A4");
assertNotNull(sheet.getCellComment(commentCellAddress));
assertEquals("Wrong starting # of comments", 1, sheet.getCellComments().size());
sheet.removeRow(sheet.getRow(commentCellAddress.getRow()));
assertEquals("There should not be any comments left!", 0, sheet.getCellComments().size());
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class TestXSSFSheetShiftRows method testBug57828_OnlyOneCommentShiftedInRow.
/** Shifting rows with cell comments only shifts comments from first such cell. Other cell comments not shifted */
@Test
public void testBug57828_OnlyOneCommentShiftedInRow() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57828.xlsx");
XSSFSheet sheet = wb.getSheetAt(0);
Comment comment1 = sheet.getCellComment(new CellAddress(2, 1));
assertNotNull(comment1);
Comment comment2 = sheet.getCellComment(new CellAddress(2, 2));
assertNotNull(comment2);
Comment comment3 = sheet.getCellComment(new CellAddress(1, 1));
assertNull("NO comment in (1,1) and it should be null", comment3);
sheet.shiftRows(2, 2, -1);
comment3 = sheet.getCellComment(new CellAddress(1, 1));
assertNotNull("Comment in (2,1) moved to (1,1) so its not null now.", comment3);
comment1 = sheet.getCellComment(new CellAddress(2, 1));
assertNull("No comment currently in (2,1) and hence it is null", comment1);
comment2 = sheet.getCellComment(new CellAddress(1, 2));
assertNotNull("Comment in (2,2) should have moved as well because of shift rows. But its not", comment2);
wb.close();
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class TestXSSFSheetShiftRows method testBug56017.
/** Shifting rows with comment result - Unreadable content error and comment deletion */
@Test
public void testBug56017() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx");
Sheet sheet = wb.getSheetAt(0);
Comment comment = sheet.getCellComment(new CellAddress(0, 0));
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
sheet.shiftRows(0, 1, 1);
// comment in row 0 is gone
comment = sheet.getCellComment(new CellAddress(0, 0));
assertNull(comment);
// comment is now in row 1
comment = sheet.getCellComment(new CellAddress(1, 0));
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close();
assertNotNull(wbBack);
Sheet sheetBack = wbBack.getSheetAt(0);
// comment in row 0 is gone
comment = sheetBack.getCellComment(new CellAddress(0, 0));
assertNull(comment);
// comment is now in row 1
comment = sheetBack.getCellComment(new CellAddress(1, 0));
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
wbBack.close();
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class TestXSSFSheet method getActiveCell.
@Test
public void getActiveCell() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
CellAddress R5 = new CellAddress("R5");
sheet.setActiveCell(R5);
assertEquals(R5, sheet.getActiveCell());
workbook.close();
}
Aggregations