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();
}
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));
}
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());
}
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);
}
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);
}
Aggregations