Example usage for org.apache.poi.ss.usermodel Comment getString

List of usage examples for org.apache.poi.ss.usermodel Comment getString

Introduction

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

Prototype

public RichTextString getString();

Source Link

Document

Fetches the rich text string of the comment

Usage

From source file:com.vaadin.addon.spreadsheet.Spreadsheet.java

License:Open Source License

private void loadCellComments(int r1, int c1, int r2, int c2) {
    Sheet sheet = getActiveSheet();//from   w w  w  .  j  av a  2s.  c o m
    for (int r = r1 - 1; r < r2; r++) {
        Row row = sheet.getRow(r);
        if (row != null && row.getZeroHeight()) {
            continue;
        }
        for (int c = c1 - 1; c < c2; c++) {
            if (sheet.isColumnHidden(c)) {
                continue;
            }

            int c_one_based = c + 1;
            int row_one_based = r + 1;

            MergedRegion region = mergedRegionContainer.getMergedRegion(c_one_based, row_one_based);
            // do not add comments that are "below" merged regions.
            // client side handles cases where comment "moves" (because
            // shifting etc.) from merged cell into basic or vice versa.
            if (region == null || region.col1 == c_one_based && region.row1 == row_one_based) {
                Comment comment = sheet.getCellComment(r, c);
                String key = SpreadsheetUtil.toKey(c_one_based, row_one_based);
                if (comment != null) {
                    // by default comments are shown when mouse is over the
                    // red
                    // triangle on the cell's top right corner. the comment
                    // position is calculated so that it is completely
                    // visible.
                    getState().cellComments.put(key, comment.getString().getString());
                    getState().cellCommentAuthors.put(key, comment.getAuthor());
                    if (comment.isVisible()) {
                        getState().visibleCellComments.add(key);
                    }
                }
                if (isMarkedAsInvalidFormula(c_one_based, row_one_based)) {
                    getState().invalidFormulaCells.add(key);
                }

            } else {
                c = region.col2 - 1;
            }
        }
    }
}

From source file:de.enerko.reports2.engine.CommentDefinition.java

License:Apache License

public CommentDefinition(final Comment comment) {
    this(comment.getString().getString(), comment.getAuthor(), comment.getColumn(), comment.getRow(), -1, -1,
            comment.isVisible());//from  w  w  w  .  j  av a2  s . c o  m
}

From source file:de.jlo.talendcomp.excel.SpreadsheetInput.java

License:Apache License

public String getCommentCellValue(int columnIndex, boolean nullable, boolean trim, boolean useLast)
        throws Exception {
    String value = null;//from w  ww .j av  a2s. c  om
    Cell cell = getCell(columnIndex);
    if (cell == null) {
        if (nullable == false) {
            throw new Exception("Cell in column " + columnIndex + " has no value!");
        }
    } else {
        Comment comment = cell.getCellComment();
        if (comment == null) {
            if (nullable == false) {
                throw new Exception("Cell in column " + columnIndex + " has no value!");
            }
        } else {
            RichTextString rt = comment.getString();
            if (rt == null) {
                if (nullable == false) {
                    throw new Exception("Cell in column " + columnIndex + " has no value!");
                }
            } else {
                value = rt.getString();
                if (value != null) {
                    value = value.trim();
                }
            }
        }
    }
    if (useLast && (value == null || value.isEmpty())) {
        value = (String) lastValueMap.get(columnIndex);
    } else {
        lastValueMap.put(columnIndex, value);
    }
    return value;
}

From source file:de.jlo.talendcomp.excel.SpreadsheetInput.java

License:Apache License

public boolean isCellCommentEmpty(int columnIndex) {
    Cell cell = getCell(columnIndex);/* w  w w . j a v  a2s .c  om*/
    if (cell == null) {
        return true;
    }
    Comment comment = cell.getCellComment();
    if (comment == null) {
        return true;
    } else {
        RichTextString rt = comment.getString();
        if (rt == null) {
            return true;
        } else {
            return rt.getString() != null ? rt.getString().trim().isEmpty() : true;
        }
    }
}

From source file:de.jlo.talendcomp.excel.SpreadsheetReferencedCellInput.java

License:Apache License

private boolean fetchCurrentCellValue(Cell cell) {
    if (cell != null) {
        currentCell = cell;/*from   www  .ja  v a  2 s.c  om*/
        currentCellValueString = getStringCellValue(cell);
        Comment comment = cell.getCellComment();
        if (comment != null) {
            currentCellComment = comment.getString().getString();
            currentCellCommentAuthor = comment.getAuthor();
        }
        CellType cellType = cell.getCellTypeEnum();
        if (cellType == CellType.BLANK) {
            currentCellValueClassName = "Object";
        } else if (cellType == CellType.STRING) {
            currentCellValueClassName = "String";
            currentCellValueObject = currentCellValueString;
        } else if (cellType == CellType.BOOLEAN) {
            currentCellValueClassName = "Boolean";
            currentCellValueBool = cell.getBooleanCellValue();
            currentCellValueObject = currentCellValueBool;
        } else if (cellType == CellType.ERROR) {
            currentCellValueClassName = "Byte";
            currentCellValueObject = cell.getErrorCellValue();
        } else if (cellType == CellType.FORMULA) {
            currentCellValueClassName = "String";
            currentCellFormula = cell.getCellFormula();
            currentCellValueString = getDataFormatter().formatCellValue(cell, getFormulaEvaluator());
            currentCellValueObject = currentCellValueString;
        } else if (cellType == CellType.NUMERIC) {
            if (DateUtil.isCellDateFormatted(cell)) {
                currentCellValueClassName = "java.util.Date";
                currentCellValueDate = cell.getDateCellValue();
                currentCellValueObject = currentCellValueDate;
            } else {
                currentCellValueClassName = "Double";
                currentCellValueNumber = cell.getNumericCellValue();
                currentCellValueObject = currentCellValueNumber;
            }
        }
        currentCellBgColor = getBgColor(cell);
        currentCellFgColor = getFgColor(cell);
        return currentCellValueObject != null;
    } else {
        return false;
    }
}

From source file:org.alanwilliamson.openbd.plugin.spreadsheet.functions.SpreadsheetGetCellComment.java

License:Open Source License

public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
    Collections.reverse(parameters);

    if (parameters.size() == 2) {
        throwException(_session, "please specify both a row and a column");
    }//from   w ww  .  j a  v a  2  s.co  m

    cfSpreadSheetData spreadsheet = (cfSpreadSheetData) parameters.get(0);
    Sheet sheet = spreadsheet.getActiveSheet();

    if (parameters.size() == 3) {
        int rowNo = parameters.get(1).getInt() - 1;
        int columnNo = parameters.get(0).getInt() - 1;

        if (rowNo < 0)
            throwException(_session, "row must be 1 or greater (" + rowNo + ")");
        if (columnNo < 0)
            throwException(_session, "column must be 1 or greater (" + columnNo + ")");

        cfStructData sd = new cfStructData();

        Row row = sheet.getRow(rowNo);
        if (row != null) {
            Cell cell = row.getCell(columnNo);
            if (cell != null) {
                Comment comment = cell.getCellComment();
                if (comment != null) {
                    sd.setData("column", new cfNumberData(columnNo));
                    sd.setData("row", new cfNumberData(rowNo));
                    sd.setData("author", new cfStringData(comment.getAuthor()));
                    sd.setData("comment", new cfStringData(comment.getString().getString()));
                }
            }
        }

        return sd;
    } else {
        cfArrayData arr = cfArrayData.createArray(1);

        Iterator<Row> rowIT = sheet.rowIterator();
        while (rowIT.hasNext()) {
            Row row = rowIT.next();

            Iterator<Cell> cellIT = row.cellIterator();
            while (cellIT.hasNext()) {
                Cell cell = cellIT.next();
                Comment comment = cell.getCellComment();
                if (comment != null) {
                    cfStructData sd = new cfStructData();
                    sd.setData("column", new cfNumberData(cell.getColumnIndex() + 1));
                    sd.setData("row", new cfNumberData(row.getRowNum() + 1));
                    sd.setData("author", new cfStringData(comment.getAuthor()));
                    sd.setData("comment", new cfStringData(comment.getString().getString()));
                    arr.addElement(sd);
                }
            }
        }

        return arr;
    }

}

From source file:org.eclipse.emfforms.internal.spreadsheet.core.transfer.EMFFormsSpreadsheetImporterImpl.java

License:Open Source License

private VDomainModelReference getDomainModelReference(Cell cell, SpreadsheetImportResult errorReports,
        EObject eObject, String sheetname, int columnId, MigrationInformation information) {
    /* get dmr comment */
    if (cell == null) {
        errorReports.reportError(Severity.ERROR,
                LocalizationServiceHelper.getString(getClass(), "ImportError_LabelCellDeleted"), //$NON-NLS-1$
                ErrorFactory.eINSTANCE.createEMFLocation(eObject),
                ErrorFactory.eINSTANCE.createSheetLocation(sheetname, columnId, 0, "NO CELL")); //$NON-NLS-1$
        return null;
    }//from   w w w. jav a2  s  .co m
    final Comment cellComment = cell.getCellComment();
    if (cellComment == null) {
        errorReports.reportError(Severity.ERROR,
                LocalizationServiceHelper.getString(getClass(), "ImportError_CommentDeleted"), //$NON-NLS-1$
                ErrorFactory.eINSTANCE.createEMFLocation(eObject),
                ErrorFactory.eINSTANCE.createSheetLocation(sheetname, columnId, 0, getStringCellValue(cell)));
        return null;
    }
    final String serializedDMR = cellComment.getString().getString();
    if (serializedDMR == null || serializedDMR.isEmpty()) {
        errorReports.reportError(Severity.ERROR,
                LocalizationServiceHelper.getString(getClass(), "ImportError_CommentEmpty"), //$NON-NLS-1$
                ErrorFactory.eINSTANCE.createEMFLocation(eObject),
                ErrorFactory.eINSTANCE.createSheetLocation(sheetname, columnId, 0, getStringCellValue(cell)));
        return null;
    }

    /* deserialize dmr */

    try {
        return deserializeDMR(serializedDMR, information);
    } catch (final IOException ex1) {
        errorReports.reportError(Severity.ERROR,
                LocalizationServiceHelper.getString(getClass(), "ImportError_DMRDeserializationFailed"), //$NON-NLS-1$
                ErrorFactory.eINSTANCE.createEMFLocation(eObject),
                ErrorFactory.eINSTANCE.createSheetLocation(sheetname, columnId, 0, getStringCellValue(cell)));
        return null;
    }

}

From source file:org.eclipse.emfforms.internal.spreadsheet.core.transfer.EMFFormsSpreadsheetImporterImpl.java

License:Open Source License

/**
 * Returns a Map from EObject-ID to Sheet-ID to Row-ID.
 *//*from  ww  w. j a v  a 2s  .c o m*/
private Map<String, Map<Integer, Integer>> parseIds(Workbook workbook, SpreadsheetImportResult errorReports) {
    final Map<String, Map<Integer, Integer>> result = new LinkedHashMap<String, Map<Integer, Integer>>();

    for (int sheetId = 0; sheetId < workbook.getNumberOfSheets(); sheetId++) {
        final Sheet sheet = workbook.getSheetAt(sheetId);
        final Row labelRow = sheet.getRow(0);
        if (labelRow == null) {
            errorReports.reportError(Severity.ERROR,
                    MessageFormat.format(
                            LocalizationServiceHelper.getString(getClass(), "ImportError_SheetEmpty"), //$NON-NLS-1$
                            sheet.getSheetName()),
                    ErrorFactory.eINSTANCE.createSheetLocation(workbook.getSheetName(sheetId), 0, 0,
                            "NO CELL")); //$NON-NLS-1$
            continue;
        }
        final Cell idColumnLabelCell = labelRow.getCell(0, Row.CREATE_NULL_AS_BLANK);
        final Comment cellComment = idColumnLabelCell.getCellComment();
        if (cellComment != null && cellComment.getString() != null
                && IGNORE_SHEET.equals(cellComment.getString().getString())) {
            continue;
        }
        final String idColumnLabel = getStringCellValue(idColumnLabelCell);
        if (!EMFFormsIdProvider.ID_COLUMN.equals(idColumnLabel)) {
            /* ID Column is missing. We have to ignore this sheet */
            errorReports.reportError(Severity.ERROR,
                    MessageFormat.format(
                            LocalizationServiceHelper.getString(getClass(), "ImportError_FirstColumnWrong"), //$NON-NLS-1$
                            EMFFormsIdProvider.ID_COLUMN, idColumnLabel),
                    ErrorFactory.eINSTANCE.createSheetLocation(workbook.getSheetName(sheetId), 0, 0,
                            "NO CELL")); //$NON-NLS-1$
            continue;
        }
        for (int rowId = 3; rowId <= sheet.getLastRowNum(); rowId++) {
            final Row row = sheet.getRow(rowId);
            if (row == null) {
                errorReports.reportError(Severity.INFO,
                        LocalizationServiceHelper.getString(getClass(), "ImportError_EmptyRow"), //$NON-NLS-1$
                        ErrorFactory.eINSTANCE.createSheetLocation(workbook.getSheetName(sheetId), 0, rowId,
                                EMFFormsIdProvider.ID_COLUMN));
                continue;
            }
            final String eObjectId = getStringCellValue(row.getCell(0, Row.CREATE_NULL_AS_BLANK));
            if (eObjectId == null || eObjectId.isEmpty()) {
                /* EObject id deleted */
                errorReports.reportError(Severity.ERROR,
                        LocalizationServiceHelper.getString(getClass(), "ImportError_NoEObjectID"), //$NON-NLS-1$
                        ErrorFactory.eINSTANCE.createSheetLocation(workbook.getSheetName(sheetId), 0, rowId,
                                EMFFormsIdProvider.ID_COLUMN));
                continue;
            }
            if (!result.containsKey(eObjectId)) {
                result.put(eObjectId, new LinkedHashMap<Integer, Integer>());
            }
            // each sheetid should only be mapped once to each eobjectid
            if (result.get(eObjectId).containsKey(sheetId)) {
                /* duplicate EObject ID */
                errorReports.reportError(Severity.ERROR,
                        LocalizationServiceHelper.getString(getClass(), "ImportError_DuplicateEObjectID"), //$NON-NLS-1$
                        ErrorFactory.eINSTANCE.createSheetLocation(workbook.getSheetName(sheetId), 0, rowId,
                                EMFFormsIdProvider.ID_COLUMN));
                continue;
            }
            result.get(eObjectId).put(sheetId, rowId);
        }
    }
    return result;
}

From source file:org.isisaddons.module.excel.dom.CellMarshaller.java

License:Apache License

private Object getCellComment(final Cell cell, final Class<?> requiredType) {
    final Comment comment = cell.getCellComment();
    if (comment == null) {
        return null;
    }/*from   ww w .  j a v a2  s .  c  o m*/
    final RichTextString commentRts = comment.getString();
    if (commentRts == null) {
        return null;
    }
    final String bookmarkStr = commentRts.getString();
    final Bookmark bookmark = new Bookmark(bookmarkStr);
    return bookmarkService.lookup(bookmark, requiredType);
}

From source file:org.olat.search.service.document.file.ExcelOOXMLDocument.java

License:Apache License

private void extractContent(final StringBuilder buffy, final XSSFWorkbook document) {
    for (int i = 0; i < document.getNumberOfSheets(); i++) {
        final XSSFSheet sheet = document.getSheetAt(i);
        buffy.append(document.getSheetName(i)).append(' ');

        // Header(s), if present
        extractHeaderFooter(buffy, sheet.getFirstHeader());
        extractHeaderFooter(buffy, sheet.getOddHeader());
        extractHeaderFooter(buffy, sheet.getEvenHeader());

        // Rows and cells
        for (final Object rawR : sheet) {
            final Row row = (Row) rawR;
            for (final Iterator<Cell> ri = row.cellIterator(); ri.hasNext();) {
                final Cell cell = ri.next();

                if (cell.getCellType() == Cell.CELL_TYPE_FORMULA
                        || cell.getCellType() == Cell.CELL_TYPE_STRING) {
                    buffy.append(cell.getRichStringCellValue().getString()).append(' ');
                } else {
                    final XSSFCell xc = (XSSFCell) cell;
                    final String rawValue = xc.getRawValue();
                    if (rawValue != null) {
                        buffy.append(rawValue).append(' ');
                    }/*from   w w w  .j  av  a 2 s . c  o  m*/

                }

                // Output the comment in the same cell as the content
                final Comment comment = cell.getCellComment();
                if (comment != null) {
                    buffy.append(comment.getString().getString()).append(' ');
                }
            }
        }

        // Finally footer(s), if present
        extractHeaderFooter(buffy, sheet.getFirstFooter());
        extractHeaderFooter(buffy, sheet.getOddFooter());
        extractHeaderFooter(buffy, sheet.getEvenFooter());
    }
}