Example usage for org.apache.poi.ss.util CellAddress getRow

List of usage examples for org.apache.poi.ss.util CellAddress getRow

Introduction

In this page you can find the example usage for org.apache.poi.ss.util CellAddress getRow.

Prototype

public int getRow() 

Source Link

Document

Get the cell address row

Usage

From source file:com.dua3.meja.model.poi.PoiSheet.java

License:Apache License

@Override
public PoiCell getCurrentCell() {
    final int currentRow, currentColumn;
    CellAddress cellRef = poiSheet.getActiveCell();
    if (cellRef != null) {
        currentRow = Math.max(getFirstRowNum(), Math.min(getLastRowNum(), cellRef.getRow()));
        currentColumn = Math.max(getFirstColNum(), Math.min(getLastColNum(), cellRef.getColumn()));
    } else {/*from  w  w w. jav  a2 s .  c o m*/
        currentRow = poiSheet.getTopRow();
        currentColumn = poiSheet.getLeftCol();
    }
    return getCell(currentRow, currentColumn);
}

From source file:offishell.excel.Excel.java

License:MIT License

public Excel calculate(Object model) {
    Map<CellAddress, XSSFComment> cellComments = sheet.getCellComments();

    VariableContext context = new VariableContext(path, false, model);

    for (Iterator<Entry<CellAddress, XSSFComment>> iterator = cellComments.entrySet().iterator(); iterator
            .hasNext();) {//from  w w w.j  a  v a2  s.c  o m
        Entry<CellAddress, XSSFComment> entry = iterator.next();

        CellAddress address = entry.getKey();
        String comment = entry.getValue().getString().getString().strip();

        entry.getValue().setVisible(false);
        XSSFCell cell = sheet.getRow(address.getRow()).getCell(address.getColumn());

        cell.setCellValue(context.apply(comment));
        cell.removeCellComment();
    }

    try {
        return save(Files.createTempFile("calculated", ".xlsx"));
    } catch (IOException e) {
        throw I.quiet(e);
    }
}

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

License:MIT License

/**
 * build command list from comments. after transfer the comment to command,
 * remove it from comments./*  w w  w  .j ava2 s. c  o m*/
 *
 * @param sheet
 *            sheet.
 * @param sheetRightCol
 *            the sheet right col
 * @param cellAttributesMap
 *            the cell attributes map
 * @return command list.
 */
private List<ConfigCommand> buildCommandListFromSheetComment(final XSSFSheet sheet, final int sheetRightCol,
        final CellAttributesMap cellAttributesMap) {
    List<ConfigCommand> commandList = new ArrayList<>();
    // if skip then return empty list.
    if (parent.isSkipConfiguration()) {
        return commandList;
    }

    Map<CellAddress, ? extends Comment> comments = null;

    try {
        // due to a poi bug. null exception throwed if no comments in the
        // sheet.
        comments = sheet.getCellComments();
    } catch (Exception ex) {
        LOG.log(Level.FINE, "Null exception throwed when no comment exists: " + ex.getLocalizedMessage(), ex);
    }
    if (comments == null) {
        return commandList;
    }

    // not sure the map is sorted. So use tree map to sort it.
    SortedSet<CellAddress> keys = new TreeSet<>(comments.keySet());
    // go through each comments
    // if found tie command then transfer it to list also remove from
    // comments.
    for (CellAddress key : keys) {
        Cell cell = sheet.getRow(key.getRow()).getCell(key.getColumn(), MissingCellPolicy.CREATE_NULL_AS_BLANK);
        buildCommandList(sheet, sheetRightCol, cell, commandList, cellAttributesMap);
    }
    return commandList;

}

From source file:uk.ac.manchester.cs.owl.semspreadsheets.ui.SheetTable.java

License:BSD License

protected void paintComponent(Graphics g) {
    try {/*from ww w  . j  a  v  a  2  s  .  co m*/
        super.paintComponent(g);
    } catch (XmlValueDisconnectedException e) {
        logger.warn("XmlValueDisconnectedException whilst repainting table");
    }
    Color oldColor = g.getColor();
    Graphics2D g2 = (Graphics2D) g;
    Stroke oldStroke = g2.getStroke();
    g2.setStroke(stroke);
    for (OntologyTermValidation ontologyTermValidation : workbookManager.getOntologyManager()
            .getOntologyTermValidations()) {
        if (ontologyTermValidation.getRange().getSheet().equals(sheet)) {
            Range validation = ontologyTermValidation.getRange();
            OntologyTermValidationDescriptor validationDescriptor = ontologyTermValidation
                    .getValidationDescriptor();
            if (!validationDescriptor.definesLiteral() && validationDescriptor.getTerms().isEmpty()) {
                g.setColor(emptyValidationColour);
            } else {
                g.setColor(validationAppliedColour);
            }
            Rectangle startRect = getCellRect(validation.getFromRow(), validation.getFromColumn(), false);
            Rectangle endRect = getCellRect(validation.getToRow(), validation.getToColumn(), false);
            int x1 = startRect.x + 1;
            int y1 = startRect.y + 1;
            int width = endRect.width + endRect.x - startRect.x - 2;
            int height = endRect.y + endRect.height - startRect.y - 2;
            Rectangle rect = new Rectangle(x1, y1, width, height);
            Composite oldComposite = g2.getComposite();
            g2.setComposite(alphaComposite2);
            g2.drawRoundRect(rect.x, rect.y, rect.width, rect.height, 5, 5);
            g2.setComposite(alphaComposite);
            g2.fill(rect);
            g2.setComposite(oldComposite);
        }
    }

    Sheet sheet = workbookManager.getSelectionModel().getSelectedRange().getSheet();

    if (sheet != null) {
        for (String entry : workbookManager.getLinkedCells(sheet.getName())) {
            Range validation;
            String cellString = entry.split(",")[0];

            Color color;
            String test = entry.split(",")[1];
            if (test.equals("BLUE")) {
                color = Color.BLUE;
            } else if (test.equals("RED")) {
                color = Color.RED;
            } else if (test.equals("MAGENTA")) {
                color = Color.MAGENTA;
            } else if (test.equals("ORANGE")) {
                color = Color.ORANGE;
            } else if (test.equals("CYAN")) {
                color = Color.CYAN;
            } else if (test.equals("GRAY")) {
                color = Color.GRAY;
            } else {
                color = Color.PINK;
            }
            int noOfColumns = Integer.parseInt(entry.split(",")[2]);
            CellAddress da = new CellAddress(cellString);
            for (int i = 0; i < noOfColumns; i++) {
                if (sheet.getCellAt(da.getColumn() + i, da.getRow()) == null) {
                    sheet.addCellAt(da.getColumn() + i, da.getRow());
                }
            }

            validation = new Range(sheet, da.getColumn(), da.getRow(), da.getColumn() + noOfColumns - 1,
                    da.getRow());

            g.setColor(color);
            Rectangle startRect = getCellRect(validation.getFromRow(), validation.getFromColumn(), false);
            Rectangle endRect = getCellRect(validation.getToRow(), validation.getToColumn(), false);
            int x1 = startRect.x + 1;
            int y1 = startRect.y + 1;
            int width = endRect.width + endRect.x - startRect.x - 2;
            int height = endRect.y + endRect.height - startRect.y - 2;
            Rectangle rect = new Rectangle(x1, y1, width, height);
            Composite oldComposite = g2.getComposite();
            g2.setComposite(alphaComposite2);
            g2.drawRoundRect(rect.x, rect.y, rect.width, rect.height, 5, 5);
            g2.setComposite(alphaComposite);
            g2.setComposite(oldComposite);

        }
    }
    g2.setStroke(oldStroke);
    g.setColor(oldColor);
}

From source file:utilities.SmapSheetXMLHandler.java

License:Apache License

/**
 * Do a check for, and output, comments in otherwise empty cells.
 *//*from w w w. j av  a2 s .c  o  m*/
private void checkForEmptyCellComments(EmptyCellCommentsCheckType type) {
    if (commentCellRefs != null && !commentCellRefs.isEmpty()) {
        // If we've reached the end of the sheet data, output any
        //  comments we haven't yet already handled
        if (type == EmptyCellCommentsCheckType.END_OF_SHEET_DATA) {
            while (!commentCellRefs.isEmpty()) {
                outputEmptyCellComment(commentCellRefs.remove());
            }
            return;
        }

        // At the end of a row, handle any comments for "missing" rows before us
        if (this.cellRef == null) {
            if (type == EmptyCellCommentsCheckType.END_OF_ROW) {
                while (!commentCellRefs.isEmpty()) {
                    if (commentCellRefs.peek().getRow() == rowNum) {
                        outputEmptyCellComment(commentCellRefs.remove());
                    } else {
                        return;
                    }
                }
                return;
            } else {
                throw new IllegalStateException(
                        "Cell ref should be null only if there are only empty cells in the row; rowNum: "
                                + rowNum);
            }
        }

        CellAddress nextCommentCellRef;
        do {
            CellAddress cellRef = new CellAddress(this.cellRef);
            CellAddress peekCellRef = commentCellRefs.peek();
            if (type == EmptyCellCommentsCheckType.CELL && cellRef.equals(peekCellRef)) {
                // remove the comment cell ref from the list if we're about to handle it alongside the cell content
                commentCellRefs.remove();
                return;
            } else {
                // fill in any gaps if there are empty cells with comment mixed in with non-empty cells
                int comparison = peekCellRef.compareTo(cellRef);
                if (comparison > 0 && type == EmptyCellCommentsCheckType.END_OF_ROW
                        && peekCellRef.getRow() <= rowNum) {
                    nextCommentCellRef = commentCellRefs.remove();
                    outputEmptyCellComment(nextCommentCellRef);
                } else if (comparison < 0 && type == EmptyCellCommentsCheckType.CELL
                        && peekCellRef.getRow() <= rowNum) {
                    nextCommentCellRef = commentCellRefs.remove();
                    outputEmptyCellComment(nextCommentCellRef);
                } else {
                    nextCommentCellRef = null;
                }
            }
        } while (nextCommentCellRef != null && !commentCellRefs.isEmpty());
    }
}