Search in sources :

Example 11 with CellAddress

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();
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) Test(org.junit.Test)

Example 12 with CellAddress

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());
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) BaseTestXSheet(org.apache.poi.ss.usermodel.BaseTestXSheet) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFTestDataSamples.openSampleWorkbook(org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 13 with CellAddress

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();
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) Comment(org.apache.poi.ss.usermodel.Comment) POITestCase.skipTest(org.apache.poi.POITestCase.skipTest) Test(org.junit.Test)

Example 14 with CellAddress

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();
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) Comment(org.apache.poi.ss.usermodel.Comment) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) POITestCase.skipTest(org.apache.poi.POITestCase.skipTest) Test(org.junit.Test)

Example 15 with CellAddress

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();
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Test(org.junit.Test)

Aggregations

CellAddress (org.apache.poi.ss.util.CellAddress)41 Test (org.junit.Test)25 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)5 Sheet (org.apache.poi.ss.usermodel.Sheet)5 Workbook (org.apache.poi.ss.usermodel.Workbook)5 POITestCase.skipTest (org.apache.poi.POITestCase.skipTest)4 Cell (org.apache.poi.ss.usermodel.Cell)4 Comment (org.apache.poi.ss.usermodel.Comment)4 Row (org.apache.poi.ss.usermodel.Row)4 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)4 CTComment (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment)4 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)2 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)2 RichTextString (org.apache.poi.ss.usermodel.RichTextString)2 CommentsTable (org.apache.poi.xssf.model.CommentsTable)2 XSSFComment (org.apache.poi.xssf.usermodel.XSSFComment)2 CTClientData (com.microsoft.schemas.office.excel.CTClientData)1