Search in sources :

Example 26 with CellAddress

use of org.apache.poi.ss.util.CellAddress in project poi by apache.

the class CellComments method main.

public static void main(String[] args) throws IOException {
    Workbook wb = new XSSFWorkbook();
    CreationHelper factory = wb.getCreationHelper();
    Sheet sheet = wb.createSheet();
    Cell cell1 = sheet.createRow(3).createCell(5);
    cell1.setCellValue("F4");
    Drawing<?> drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = factory.createClientAnchor();
    Comment comment1 = drawing.createCellComment(anchor);
    RichTextString str1 = factory.createRichTextString("Hello, World!");
    comment1.setString(str1);
    comment1.setAuthor("Apache POI");
    cell1.setCellComment(comment1);
    Cell cell2 = sheet.createRow(2).createCell(2);
    cell2.setCellValue("C3");
    Comment comment2 = drawing.createCellComment(anchor);
    RichTextString str2 = factory.createRichTextString("XSSF can set cell comments");
    //apply custom font to the text in the comment
    Font font = wb.createFont();
    font.setFontName("Arial");
    font.setFontHeightInPoints((short) 14);
    font.setBold(true);
    font.setColor(IndexedColors.RED.getIndex());
    str2.applyFont(font);
    comment2.setString(str2);
    comment2.setAuthor("Apache POI");
    comment2.setAddress(new CellAddress("C3"));
    String fname = "comments.xlsx";
    FileOutputStream out = new FileOutputStream(fname);
    wb.write(out);
    out.close();
    wb.close();
}
Also used : Comment(org.apache.poi.ss.usermodel.Comment) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) RichTextString(org.apache.poi.ss.usermodel.RichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Font(org.apache.poi.ss.usermodel.Font) CellAddress(org.apache.poi.ss.util.CellAddress) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell)

Example 27 with CellAddress

use of org.apache.poi.ss.util.CellAddress in project poi by apache.

the class TestCommentsTable method removeComment.

@Test
public void removeComment() throws Exception {
    final CellAddress addrA1 = new CellAddress("A1");
    final CellAddress addrA2 = new CellAddress("A2");
    final CellAddress addrA3 = new CellAddress("A3");
    CommentsTable sheetComments = new CommentsTable();
    CTComment a1 = sheetComments.newComment(addrA1);
    CTComment a2 = sheetComments.newComment(addrA2);
    CTComment a3 = sheetComments.newComment(addrA3);
    assertSame(a1, sheetComments.getCTComment(addrA1));
    assertSame(a2, sheetComments.getCTComment(addrA2));
    assertSame(a3, sheetComments.getCTComment(addrA3));
    assertEquals(3, sheetComments.getNumberOfComments());
    assertTrue(sheetComments.removeComment(addrA1));
    assertEquals(2, sheetComments.getNumberOfComments());
    assertNull(sheetComments.getCTComment(addrA1));
    assertSame(a2, sheetComments.getCTComment(addrA2));
    assertSame(a3, sheetComments.getCTComment(addrA3));
    assertTrue(sheetComments.removeComment(addrA2));
    assertEquals(1, sheetComments.getNumberOfComments());
    assertNull(sheetComments.getCTComment(addrA1));
    assertNull(sheetComments.getCTComment(addrA2));
    assertSame(a3, sheetComments.getCTComment(addrA3));
    assertTrue(sheetComments.removeComment(addrA3));
    assertEquals(0, sheetComments.getNumberOfComments());
    assertNull(sheetComments.getCTComment(addrA1));
    assertNull(sheetComments.getCTComment(addrA2));
    assertNull(sheetComments.getCTComment(addrA3));
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) Test(org.junit.Test)

Example 28 with CellAddress

use of org.apache.poi.ss.util.CellAddress in project poi by apache.

the class TestCellAddress method testGetColumn.

@Test
public void testGetColumn() {
    final CellAddress addr = new CellAddress(6, 4);
    assertEquals(4, addr.getColumn());
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) Test(org.junit.Test)

Example 29 with CellAddress

use of org.apache.poi.ss.util.CellAddress in project poi by apache.

the class TestCellAddress method testConstructors.

@Test
public void testConstructors() {
    CellAddress cellAddress;
    final CellReference cellRef = new CellReference("Sheet1", 0, 0, true, true);
    final String address = "A1";
    final int row = 0;
    final int col = 0;
    cellAddress = new CellAddress(row, col);
    assertEquals(CellAddress.A1, cellAddress);
    cellAddress = new CellAddress(address);
    assertEquals(CellAddress.A1, cellAddress);
    cellAddress = new CellAddress(cellRef);
    assertEquals(CellAddress.A1, cellAddress);
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) Test(org.junit.Test)

Example 30 with CellAddress

use of org.apache.poi.ss.util.CellAddress in project poi by apache.

the class TestCellAddress method testCompareTo.

@Test
public void testCompareTo() {
    final CellAddress A1 = new CellAddress(0, 0);
    final CellAddress A2 = new CellAddress(1, 0);
    final CellAddress B1 = new CellAddress(0, 1);
    final CellAddress B2 = new CellAddress(1, 1);
    assertEquals(0, A1.compareTo(A1));
    assertEquals(-1, A1.compareTo(B1));
    assertEquals(-1, A1.compareTo(A2));
    assertEquals(-1, A1.compareTo(B2));
    assertEquals(1, B1.compareTo(A1));
    assertEquals(0, B1.compareTo(B1));
    assertEquals(-1, B1.compareTo(A2));
    assertEquals(-1, B1.compareTo(B2));
    assertEquals(1, A2.compareTo(A1));
    assertEquals(1, A2.compareTo(B1));
    assertEquals(0, A2.compareTo(A2));
    assertEquals(-1, A2.compareTo(B2));
    assertEquals(1, B2.compareTo(A1));
    assertEquals(1, B2.compareTo(B1));
    assertEquals(1, B2.compareTo(A2));
    assertEquals(0, B2.compareTo(B2));
    CellAddress[] sorted = { A1, B1, A2, B2 };
    CellAddress[] unsorted = { B1, B2, A1, A2 };
    assumeTrue(!sorted.equals(unsorted));
    Arrays.sort(unsorted);
    assertArrayEquals(sorted, unsorted);
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) 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