List of usage examples for org.apache.poi.ss.usermodel Cell removeCellComment
void removeCellComment();
From source file:com.vaadin.addon.spreadsheet.action.InsertDeleteCellCommentAction.java
License:Open Source License
@Override public void executeActionOnSelection(Spreadsheet spreadsheet, SelectionChangeEvent event) { Sheet sheet = spreadsheet.getActiveSheet(); CellReference cr = event.getSelectedCellReference(); boolean cellCreated = false, rowCreated = false, commentEdited = false; Row row = sheet.getRow(cr.getRow()); if (row == null) { row = sheet.createRow(cr.getRow()); rowCreated = true;/*from w ww . ja v a2 s . c o m*/ } Cell cell = spreadsheet.getCell(cr); if (cell == null) { cell = row.createCell(cr.getCol()); cellCreated = true; } if (cell.getCellComment() == null) { createCellComment(spreadsheet, sheet, cell, cr); commentEdited = true; } else { cell.removeCellComment(); if (cellCreated) { sheet.getRow(cr.getRow()).removeCell(cell); } if (rowCreated) { sheet.removeRow(sheet.getRow(cr.getRow())); } } if (cell != null) { spreadsheet.refreshCells(cell); } if (commentEdited) { spreadsheet.editCellComment(cr); } }
From source file:de.jlo.talendcomp.excel.SpreadsheetOutput.java
License:Apache License
private void setCellComment(Cell cell, String comment) { if (comment == null || comment.trim().isEmpty()) { cell.removeCellComment(); } else {//from w w w.java2 s . c o m Comment c = cell.getCellComment(); if (c == null) { ClientAnchor anchor = creationHelper.createClientAnchor(); anchor.setRow1(cell.getRowIndex()); anchor.setRow2(cell.getRowIndex() + commentHeight); anchor.setCol1(cell.getColumnIndex() + 1); anchor.setCol2(cell.getColumnIndex() + commentWidth + 1); anchor.setAnchorType(AnchorType.MOVE_AND_RESIZE); c = getDrawing().createCellComment(anchor); c.setVisible(false); if (commentAuthor != null) { c.setAuthor(commentAuthor); } cell.setCellComment(c); } RichTextString rts = creationHelper.createRichTextString(comment); c.setString(rts); } }
From source file:org.tiefaces.components.websheet.configuration.ConfigurationHandler.java
License:MIT License
/** * build command list from comment.//from w ww .java2 s . c o m * * @param sheet * sheet. * @param sheetRightCol * sheet right column. * @param cell * the cell * @param cList * command list. * @param cellAttributesMap * the cell attributes map * @return command list. */ private List<ConfigCommand> buildCommandList(final Sheet sheet, final int sheetRightCol, final Cell cell, final List<ConfigCommand> cList, final CellAttributesMap cellAttributesMap) { Comment comment = cell.getCellComment(); String text = comment.getString().getString(); String[] commentLines = text.split("\\n"); StringBuilder newComment = new StringBuilder(); boolean changed = false; for (String commentLine : commentLines) { String line = commentLine.trim(); if (ParserUtility.isCommandString(line)) { processCommandLine(sheet, cell, line, cList, sheetRightCol); changed = true; } else if (ParserUtility.isEmptyMethodString(line) || ParserUtility.isMethodString(line)) { processMethodLine(cell, line, cellAttributesMap); changed = true; } else { if (newComment.length() > 0) { newComment.append("\\n" + commentLine); } else { newComment.append(commentLine); } } } if (!changed) { moveCommentToMap(cell, text, cellAttributesMap.getTemplateCommentMap(), true); } else { // reset comment string if changed if (newComment.length() > 0) { moveCommentToMap(cell, newComment.toString(), cellAttributesMap.getTemplateCommentMap(), true); CreationHelper factory = sheet.getWorkbook().getCreationHelper(); RichTextString str = factory.createRichTextString(newComment.toString()); comment.setString(str); } else { // remove cell comment if new comment become empty. cell.removeCellComment(); } } return cList; }