Package org.apache.poi.ss.usermodel

Examples of org.apache.poi.ss.usermodel.Comment


            XSSFCell xc = (XSSFCell)cell;
            text.append(xc.getRawValue());
          }
         
          // Output the comment, if requested and exists
            Comment comment = cell.getCellComment();
          if(includeCellComments && comment != null) {
              // Replace any newlines with spaces, otherwise it
              //  breaks the output
              String commentText = comment.getString().getString().replace('\n', ' ');
              text.append(" Comment by "+comment.getAuthor()+": "+commentText);
          }
         
          if(ri.hasNext())
            text.append("\t");
        }
View Full Code Here


        Row row = sheet.createRow(9);
        Cell cell = row.createCell((short)2);
        Cell cell3 = row.createCell((short)3);
       
        // Create a comment
        Comment comment = comments.addComment();
        comment.setAuthor(TEST_C10_AUTHOR);
       
        // Set a comment for C10 cell
        cell.setCellComment(comment);
       
        CTCell ctCell = ctWorksheet.getSheetData().getRowArray(0).getCArray(0);
View Full Code Here

    assertNotNull( r5.getCell(2).getCellComment() );
    assertNotNull( r7.getCell(2).getCellComment() );
   
    // Check they have what we expect
    // TODO: Rich text formatting
    Comment cc5 = r5.getCell(2).getCellComment();
    Comment cc7 = r7.getCell(2).getCellComment();
   
    assertEquals("Nick Burch", cc5.getAuthor());
    assertEquals("Nick Burch:\nThis is a comment", cc5.getString().getString());
    assertEquals(4, cc5.getRow());
    assertEquals(2, cc5.getColumn());
   
    assertEquals("Nick Burch", cc7.getAuthor());
    assertEquals("Nick Burch:\nComment #1\n", cc7.getString().getString());
    assertEquals(6, cc7.getRow());
    assertEquals(2, cc7.getColumn());
  }
View Full Code Here

    assertFalse( ((XSSFSheet)sheet2).hasComments() );
   
    // Change on comment on sheet 1, and add another into
    //  sheet 2
    Row r5 = sheet1.getRow(4);
    Comment cc5 = r5.getCell(2).getCellComment();
    cc5.setAuthor("Apache POI");
    cc5.setString(new XSSFRichTextString("Hello!"));
   
    Row r2s2 = sheet2.createRow(2);
    Cell c1r2s2 = r2s2.createCell(1);
    assertNull(c1r2s2.getCellComment());
   
    Comment cc2 = sheet2.createComment();
    cc2.setAuthor("Also POI");
    cc2.setString(new XSSFRichTextString("A new comment"));
    c1r2s2.setCellComment(cc2);
   
   
    // Save, and re-load the file
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
View Full Code Here

    Cell r1c1 = r1.createCell(0);
    r1c1.setCellValue(2.2);
   
    assertEquals(0, s1.getNumberOfComments());
   
    Comment c1 = s1.createComment();
    c1.setAuthor("Author 1");
    c1.setString(new XSSFRichTextString("Comment 1"));
    r1c1.setCellComment(c1);
   
    assertEquals(1, s1.getNumberOfComments());
   
    // Save and re-load
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    wb.write(baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
   
    wb = new XSSFWorkbook(Package.open(bais));
    s1 = (XSSFSheet)wb.getSheetAt(0);
   
    assertEquals(1, s1.getNumberOfComments());
    assertNotNull(s1.getRow(0).getCell(0).getCellComment());
    assertEquals("Author 1", s1.getRow(0).getCell(0).getCellComment().getAuthor());
    assertEquals("Comment 1", s1.getRow(0).getCell(0).getCellComment().getString().getString());
   
    // Now add an orphaned one
    Comment c2 = s1.createComment();
    c2.setAuthor("Author 2");
    c2.setString(new XSSFRichTextString("Second Comment"));
    c2.setRow(0);
    c2.setColumn((short)1);
    assertEquals(2, s1.getNumberOfComments());
   
    // Save and re-load
    baos = new ByteArrayOutputStream();
    wb.write(baos);
View Full Code Here

        anchor.setCol2(cell.getColumnIndex()+1);
        anchor.setRow1(row.getRowNum());
        anchor.setRow2(row.getRowNum()+3);
       
        Drawing drawing = sheet.createDrawingPatriarch();
        Comment comment1 = drawing.createCellComment(anchor);
       
        RichTextString commentRtf = creationHelper.createRichTextString(commentText);
       
        comment1.setString(commentRtf);
        Comment comment = comment1;
        cell.setCellComment(comment);
    }
View Full Code Here

        }
        return null;
    }

    private Object getCellComment(final Cell cell, final Class<?> requiredType) {
        final Comment comment = cell.getCellComment();
        if(comment == null) {
            return null;
        }
        final RichTextString commentRts = comment.getString();
        if(commentRts == null) {
            return null;
        }
        final String bookmarkStr = commentRts.getString();
        final Bookmark bookmark = new Bookmark(bookmarkStr);
View Full Code Here

                        }

                    }

                    // Output the comment in the same cell as the content
                    Comment comment = cell.getCellComment();
                    if (comment != null) {
                        xhtml.characters(comment.getString().getString());
                    }

                    xhtml.endElement("td");
                }
                xhtml.endElement("tr");
View Full Code Here

       anchor.setCol1(0);
       anchor.setCol2(4);
       anchor.setRow1(0);
       anchor.setRow2(1);

       Comment comment1 = drawing.createCellComment(anchor);
       comment1.setString(
             factory.createRichTextString("I like this cell. It's my favourite."));
       comment1.setAuthor("Bob T. Fish");
      
       Comment comment2 = drawing.createCellComment(anchor);
       comment2.setString(
             factory.createRichTextString("This is much less fun..."));
       comment2.setAuthor("Bob T. Fish");

       Cell c1 = sh1.getRow(0).createCell(4);
       c1.setCellValue(2.3);
       c1.setCellComment(comment1);
      
View Full Code Here

            XSSFCell xc = (XSSFCell)cell;
            text.append(xc.getRawValue());
          }

          // Output the comment, if requested and exists
            Comment comment = cell.getCellComment();
          if(includeCellComments && comment != null) {
              // Replace any newlines with spaces, otherwise it
              //  breaks the output
              String commentText = comment.getString().getString().replace('\n', ' ');
              text.append(" Comment by ").append(comment.getAuthor()).append(": ").append(commentText);
          }

          if(ri.hasNext())
            text.append("\t");
        }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.usermodel.Comment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.