Example usage for org.apache.poi.xssf.usermodel XSSFComment getString

List of usage examples for org.apache.poi.xssf.usermodel XSSFComment getString

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFComment getString.

Prototype

@Override
public XSSFRichTextString getString() 

Source Link

Usage

From source file:org.tiefaces.components.websheet.utility.CellUtility.java

License:MIT License

/**
 * clone existing comments into new cell comment.
 * //from  ww  w  . ja  v a  2s  .  c o  m
 * @param sourceCell
 *            source cell.
 * @param newCell
 *            target cell.
 */

public static void cloneComment(final Cell sourceCell, final Cell newCell) {

    XSSFSheet sheet = (XSSFSheet) newCell.getSheet();
    CreationHelper factory = sheet.getWorkbook().getCreationHelper();
    Drawing drawing = sheet.createDrawingPatriarch();
    XSSFComment sourceComment = (XSSFComment) sourceCell.getCellComment();
    // Below code are from POI busy manual.
    // When the comment box is visible, have it show in a 1x3 space
    ClientAnchor anchor = createCommentAnchor(newCell, factory);
    // Create the comment and set the text+author
    Comment comment = drawing.createCellComment(anchor);
    RichTextString str = factory.createRichTextString(sourceComment.getString().toString());
    comment.setString(str);
    comment.setAuthor(sourceComment.getAuthor());
    // Assign the comment to the cell
    newCell.setCellComment(comment);
    comment.setColumn(newCell.getColumnIndex());
    comment.setRow(newCell.getRowIndex());
    // As POI doesn't has well support for comments,
    // So we have to use low level api to match the comments.
    matchCommentSettings(newCell, sourceCell);
}