Example usage for org.apache.poi.ss.usermodel Cell getCellComment

List of usage examples for org.apache.poi.ss.usermodel Cell getCellComment

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Cell getCellComment.

Prototype

Comment getCellComment();

Source Link

Document

Returns comment associated with this cell

Usage

From source file:org.tiefaces.components.websheet.configuration.ConfigurationHandler.java

License:MIT License

/**
 * build command list from comment./*from  w w w .j av a 2  s.com*/
 *
 * @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;
}

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

License:MIT License

/**
 * Copy cell.//from w w  w  . j a va  2  s  .com
 *
 * @param destSheet
 *            the dest sheet
 * @param sourceRow
 *            the source row
 * @param newRow
 *            the new row
 * @param cellIndex
 *            the cell index
 * @param checkLock
 *            the check lock
 * @return the int
 */
public static Cell copyCell(final Sheet destSheet, final Row sourceRow, final Row newRow, final int cellIndex,
        final boolean checkLock) {
    // If the old cell is null jump to next cell
    Cell sourceCell = sourceRow.getCell(cellIndex);
    if (sourceCell == null) {
        return null;
    }
    // If source cell is dest cell refresh it
    boolean refreshCell = false;
    if (sourceRow.equals(newRow) && (sourceCell.getColumnIndex() == cellIndex)) {
        sourceRow.removeCell(sourceCell);
        refreshCell = true;
    }
    Cell newCell = newRow.createCell(cellIndex);
    try {
        if (!refreshCell && (sourceCell.getCellComment() != null)) {
            // If there is a cell comment, copy
            cloneComment(sourceCell, newCell);
        }
        copyCellSetStyle(destSheet, sourceCell, newCell);
        copyCellSetValue(sourceCell, newCell, checkLock);
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, "copy cell set error = " + ex.getLocalizedMessage(), ex);
    }

    return newCell;
}

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

License:MIT License

/**
 * clone existing comments into new cell comment.
 * /*  w  w  w. ja  v a2s  .co  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);
}

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

License:MIT License

/**
 * Creates the or insert comment./*  w  ww. j  a v  a2 s .c  o  m*/
 *
 * @param cell the cell
 * @param commentStr the comment str
 */
public static void createOrInsertComment(final Cell cell, final String commentStr) {

    XSSFSheet sheet = (XSSFSheet) cell.getSheet();
    CreationHelper factory = sheet.getWorkbook().getCreationHelper();
    Drawing drawing = sheet.createDrawingPatriarch();
    Comment comment = cell.getCellComment();
    String originStr = "";
    if (comment == null) {
        // Below code are from POI busy manual.
        // When the comment box is visible, have it show in a 1x3 space
        ClientAnchor anchor = createCommentAnchor(cell, factory);
        // Create the comment and set the text+author
        comment = drawing.createCellComment(anchor);
    } else {
        originStr = comment.getString().getString() + "\n";
    }
    originStr += commentStr;
    RichTextString str = factory.createRichTextString(originStr);
    comment.setString(str);
    comment.setAuthor("");
    // Assign the comment to the cell
    cell.setCellComment(comment);
    comment.setColumn(cell.getColumnIndex());
    comment.setRow(cell.getRowIndex());
}

From source file:org.unhcr.eg.odk.utilities.xlsform.excel.ExcelFileUtility.java

protected static void copyContent(Sheet sheetSource, Sheet sheetDestination) {
    //Iterate through each rows from first sheet
    Iterator<Row> rowIterator = sheetSource.iterator();
    int i = 0;/*  w  w  w .  j a v a2 s  .c om*/
    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();
        Row rowDestination = sheetDestination.createRow(i);
        i++;
        //For each row, iterate through each columns
        Iterator<Cell> cellIterator = row.cellIterator();
        int j = 0;
        while (cellIterator.hasNext()) {
            Cell cell = cellIterator.next();
            Cell cellDestination = rowDestination.createCell(j);
            j++;
            cellDestination.setCellComment(cell.getCellComment());
            //                cellDestination.setCellStyle(cell.getCellStyle());
            cellDestination.setCellType(cell.getCellType());
            switch (cell.getCellType()) {
            case Cell.CELL_TYPE_BOOLEAN:
                cellDestination.setCellValue(cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_NUMERIC:
                if (DateUtil.isCellDateFormatted(cell)) {
                    cellDestination.setCellValue(cell.getDateCellValue());
                } else {
                    cellDestination.setCellValue(cell.getNumericCellValue());
                }
                break;
            case Cell.CELL_TYPE_STRING:
                cellDestination.setCellValue(cell.getRichStringCellValue());
                break;
            case Cell.CELL_TYPE_BLANK:
                cellDestination.setCellValue(cell.getStringCellValue());
                break;
            case Cell.CELL_TYPE_ERROR:
                cellDestination.setCellValue(cell.getErrorCellValue());
                break;
            case Cell.CELL_TYPE_FORMULA:
                cellDestination.setCellFormula(cell.getCellFormula());
                break;
            }

        }

    }

}

From source file:org.wandora.application.tools.extractors.excel.AbstractExcelExtractor.java

License:Open Source License

public void associateToComment(Cell cell, TopicMap tm) throws TopicMapException {
    if (cell.getCellComment() != null) {
        Topic commentTypeTopic = getCommentTypeTopic(tm);
        Topic commentTopic = getCommentTopic(cell, tm);
        Topic cellTypeTopic = getCellTypeTopic(tm);
        Topic cellTopic = getCellTopic(cell, tm);

        if (commentTypeTopic != null && commentTopic != null && cellTypeTopic != null && cellTopic != null) {
            Association a = tm.createAssociation(commentTypeTopic);
            a.addPlayer(cellTopic, cellTypeTopic);
            a.addPlayer(commentTopic, commentTypeTopic);
        }//from www .ja va2s  .  c  om
    }
}

From source file:org.wandora.application.tools.extractors.excel.AbstractExcelExtractor.java

License:Open Source License

public Topic getCommentTopic(Cell cell, TopicMap tm) throws TopicMapException {
    Comment comment = cell.getCellComment();
    if (comment != null) {
        RichTextString rts = comment.getString();
        String str = rts.getString();
        String basename = str.replace('\n', ' ');
        basename = basename.replace('\r', ' ');
        basename = basename.replace('\t', ' ');
        Topic topic = getOrCreateTopic(tm, EXCEL_COMMENT_SI_PREFIX + "/" + urlEncode(basename), basename);
        topic.setData(getCommentTypeTopic(tm), tm.getTopic(XTMPSI.getLang(DEFAULT_LANG)), str);
        topic.addType(getCommentTypeTopic(tm));
        return topic;
    }/*from w  ww  . j  a v a  2 s  .  c o m*/
    return null;
}

From source file:parser.CloudDSFPlusParser.java

License:Apache License

/**
 * Generates a new outcome.//from  w w w  .j  a va2  s. c o  m
 * 
 * @param cell current cell in the excel file
 * @param decisionId id of the decision
 * @param decisionPointId id of the decision point
 * @param outcomeId id of the outcome
 * @param row current row in the excel file
 * @return
 */
private Outcome generateOutcome(Cell cell, int decisionId, int decisionPointId, int outcomeId, Row row) {
    String label = cell.getStringCellValue();
    String description = row.getCell(outDescCol).getStringCellValue();
    String abbrev = cell.getCellComment().getString().getString();
    Outcome out = new Outcome(label, outcomeId, decisionPointId, decisionId, description, null, abbrev);
    return out;
}

From source file:parser.CloudDSFPlusParser.java

License:Apache License

/**
 * Generates a new decision./* w w w .  ja v  a2 s . c  o m*/
 * 
 * @param cell current cell in the excel file
 * @param decisionId id of the decision
 * @param decisionPointId id of the decision point
 * @param row current row in the excel file
 * @return
 */
private Decision generateDecision(Cell cell, int decisionId, int decisionPointId, Row row) {
    String label = cell.getStringCellValue();
    String classification = row.getCell(decClassCol).getStringCellValue();
    String description = row.getCell(decDescCol).getStringCellValue();
    String abbrev = cell.getCellComment().getString().getString();
    Decision dec = new Decision(label, decisionId, decisionPointId, decisionPointId, classification,
            description, null, abbrev);
    return dec;
}

From source file:parser.CloudDSFPlusParser.java

License:Apache License

/**
 * Generates a new decision point./*from   w w w .j  a  v  a  2  s.  c o  m*/
 * 
 * @param cell current cell in the excel file
 * @param decisionPointId id of the decision point
 * @param row current row in the excel file
 * @return
 */
private DecisionPoint generateDecisionPoint(Cell cell, int decisionPointId, Row row) {
    String label = cell.getStringCellValue();
    String classification = row.getCell(dpClassCol).getStringCellValue();
    String description = row.getCell(dpDescCol).getStringCellValue();
    String abbrev = cell.getCellComment().getString().getString();
    DecisionPoint dp = new DecisionPoint(label, decisionPointId, decisionPointId, classification, description,
            null, abbrev);
    return dp;
}