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

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

Introduction

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

Prototype

Row getRow();

Source Link

Document

Returns the Row this cell belongs to

Usage

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

License:MIT License

/**
 * Prepare context and attrs for cell./*from www. j  ava2 s  . c  o m*/
 *
 * @param poiCell
 *            the poi cell
 * @param fullName
 *            the full name
 * @param cellHelper
 *            the cell helper
 * @return the string
 */
public static String prepareContextAndAttrsForCell(Cell poiCell, String fullName, CellHelper cellHelper) {

    if (fullName == null) {
        return null;
    }
    String saveAttrList = SaveAttrsUtility.getSaveAttrListFromRow(poiCell.getRow());
    if (saveAttrList != null) {
        String saveAttr = SaveAttrsUtility.getSaveAttrFromList(poiCell.getColumnIndex(), saveAttrList);
        if (saveAttr != null) {
            cellHelper.restoreDataContext(fullName);
            return saveAttr;
        }

    }
    return null;
}

From source file:ru.icc.cells.ssdc.DataLoader.java

License:Apache License

private void fillCell(CCell cell, Cell excelCell) {
    String rawTextualContent = null;
    CellType cellType = null;//w ww. ja  va 2  s .  com

    String text = null;
    if (withoutSuperscript) {
        if (hasSuperscriptText(excelCell)) {
            text = getNotSuperscriptText(excelCell);
        } else {
            text = getText(excelCell);
        }
    } else {
        text = getText(excelCell);
    }
    cell.setText(text);

    rawTextualContent = getFormatCellValue(excelCell);
    cell.setRawText(rawTextualContent);

    switch (excelCell.getCellType()) {
    case Cell.CELL_TYPE_NUMERIC:
        if (DateUtil.isCellDateFormatted(excelCell)) {
            //rawTextualContent = "DATE"; // TODO - ? 
            cellType = CellType.DATE;
        } else {
            cellType = CellType.NUMERIC;
        }
        break;

    case Cell.CELL_TYPE_STRING:
        cellType = CellType.STRING;
        break;

    case Cell.CELL_TYPE_BOOLEAN:
        cellType = CellType.BOOLEAN;
        break;

    case Cell.CELL_TYPE_FORMULA:
        cellType = CellType.FORMULA;
        break;

    case Cell.CELL_TYPE_BLANK:
        cellType = CellType.BLANK;
        break;

    case Cell.CELL_TYPE_ERROR:
        cellType = CellType.ERROR;
        break;
    }

    cell.setId(this.cellCount);

    cell.setCellType(cellType);

    int height = excelCell.getRow().getHeight();
    cell.setHeight(height);

    int width = excelCell.getSheet().getColumnWidth(excelCell.getColumnIndex());
    cell.setWidth(width);

    CellStyle excelCellStyle = excelCell.getCellStyle();
    CStyle cellStyle = cell.getStyle();
    fillCellStyle(cellStyle, excelCellStyle);

    String reference = new CellReference(excelCell).formatAsString();
    cell.setProvenance(reference);

    this.cellCount++;
}

From source file:uk.co.spudsoft.birt.emitters.excel.handlers.CellContentHandler.java

License:Open Source License

/**
 * Set the contents of an empty cell./*from   w  ww  .j a  v  a 2s .  c  om*/
 * This should now be the only way in which a cell value is set (cells should not be modified). 
 * @param value
 * The value to set.
 * @param element
 * The BIRT element supplying the value, used to set the style of the cell.
 */
private <T> void setCellContents(Cell cell, Object value) {
    log.debug("Setting cell[", cell.getRow().getRowNum(), ",", cell.getColumnIndex(), "] value to ", value);
    if (value instanceof Double) {
        // cell.setCellType(Cell.CELL_TYPE_NUMERIC);
        cell.setCellValue((Double) value);
        lastValue = value;
    } else if (value instanceof Integer) {
        // cell.setCellType(Cell.CELL_TYPE_NUMERIC);
        cell.setCellValue((Integer) value);
        lastValue = value;
    } else if (value instanceof Long) {
        // cell.setCellType(Cell.CELL_TYPE_NUMERIC);
        cell.setCellValue((Long) value);
        lastValue = value;
    } else if (value instanceof Date) {
        // cell.setCellType(Cell.CELL_TYPE_NUMERIC);
        cell.setCellValue((Date) value);
        lastValue = value;
    } else if (value instanceof Boolean) {
        // cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
        cell.setCellValue(((Boolean) value).booleanValue());
        lastValue = value;
    } else if (value instanceof BigDecimal) {
        // cell.setCellType(Cell.CELL_TYPE_NUMERIC);
        cell.setCellValue(((BigDecimal) value).doubleValue());
        lastValue = value;
    } else if (value instanceof String) {
        // cell.setCellType(Cell.CELL_TYPE_STRING);
        cell.setCellValue((String) value);
        lastValue = value;
    } else if (value instanceof RichTextString) {
        // cell.setCellType(Cell.CELL_TYPE_STRING);
        cell.setCellValue((RichTextString) value);
        lastValue = value;
    } else if (value != null) {
        log.debug("Unhandled data: ", (value == null ? "<null>" : value));
        // cell.setCellType(Cell.CELL_TYPE_STRING);
        cell.setCellValue(value.toString());
        lastValue = value;
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.handlers.PageHandler.java

License:Open Source License

/**
 * <p>/*from w ww  . j ava  2 s. c  o  m*/
 * Process a CellImage from the images list and place the image on the sheet.
 * </p><p>
 * This involves changing the row height as necesssary and determining the column spread of the image.
 * </p>
 * @param cellImage
 * The image to be placed on the sheet.
 */
private void processCellImage(HandlerState state, Drawing drawing, CellImage cellImage) {
    Coordinate location = cellImage.location;

    Cell cell = state.currentSheet.getRow(location.getRow()).getCell(location.getCol());

    IImageContent image = cellImage.image;

    StyleManagerUtils smu = state.getSmu();
    float ptHeight = cell.getRow().getHeightInPoints();
    if (image.getHeight() != null) {
        ptHeight = smu.fontSizeInPoints(image.getHeight().toString());
    }

    // Get image width
    int endCol = cell.getColumnIndex();
    double lastColWidth = ClientAnchorConversions
            .widthUnits2Millimetres((short) state.currentSheet.getColumnWidth(endCol)) + 2.0;
    int dx = smu.anchorDxFromMM(lastColWidth, lastColWidth);
    double mmWidth = 0.0;
    if (smu.isAbsolute(image.getWidth())) {
        mmWidth = image.getWidth().convertTo(DimensionType.UNITS_MM);
    } else if (smu.isPixels(image.getWidth())) {
        mmWidth = ClientAnchorConversions.pixels2Millimetres(image.getWidth().getMeasure());
    }
    // Allow image to span multiple columns
    CellRangeAddress mergedRegion = getMergedRegionBegunBy(state.currentSheet, location.getRow(),
            location.getCol());
    if ((cellImage.spanColumns) || (mergedRegion != null)) {
        log.debug("Image size: ", image.getWidth(), " translates as mmWidth = ", mmWidth);
        if (mmWidth > 0) {
            double mmAccumulatedWidth = 0;
            int endColLimit = cellImage.spanColumns ? 256 : mergedRegion.getLastColumn();
            for (endCol = cell.getColumnIndex(); mmAccumulatedWidth < mmWidth
                    && endCol < endColLimit; ++endCol) {
                lastColWidth = ClientAnchorConversions
                        .widthUnits2Millimetres((short) state.currentSheet.getColumnWidth(endCol)) + 2.0;
                mmAccumulatedWidth += lastColWidth;
                log.debug("lastColWidth = ", lastColWidth, "; mmAccumulatedWidth = ", mmAccumulatedWidth);
            }
            if (mmAccumulatedWidth > mmWidth) {
                mmAccumulatedWidth -= lastColWidth;
                --endCol;
                double mmShort = mmWidth - mmAccumulatedWidth;
                dx = smu.anchorDxFromMM(mmShort, lastColWidth);
            }
        }
    } else {
        float widthRatio = (float) (mmWidth / lastColWidth);
        ptHeight = ptHeight / widthRatio;
    }

    int rowsSpanned = state.findRowsSpanned(cell.getRowIndex(), cell.getColumnIndex());
    float neededRowHeightPoints = ptHeight;

    for (int i = 0; i < rowsSpanned; ++i) {
        int rowIndex = cell.getRowIndex() + 1 + i;
        neededRowHeightPoints -= state.currentSheet.getRow(rowIndex).getHeightInPoints();
    }

    if (neededRowHeightPoints > cell.getRow().getHeightInPoints()) {
        cell.getRow().setHeightInPoints(neededRowHeightPoints);
    }

    // ClientAnchor anchor = wb.getCreationHelper().createClientAnchor();
    ClientAnchor anchor = state.getWb().getCreationHelper().createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setRow1(cell.getRowIndex());
    anchor.setCol2(endCol);
    anchor.setRow2(cell.getRowIndex() + rowsSpanned);
    anchor.setDx2(dx);
    anchor.setDy2(smu.anchorDyFromPoints(ptHeight, cell.getRow().getHeightInPoints()));
    anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE);
    drawing.createPicture(anchor, cellImage.imageIdx);
}

From source file:uk.co.spudsoft.birt.emitters.excel2.handlers.PageHandler.java

License:Open Source License

/**
 * <p>/*from  ww w.ja  v a  2 s . c  o m*/
 * Process a CellImage from the images list and place the image on the sheet.
 * </p><p>
 * This involves changing the row height as necesssary and determining the column spread of the image.
 * </p>
 * @param cellImage
 * The image to be placed on the sheet.
 */
private void processCellImage(HandlerState state, Drawing drawing, CellImage cellImage) {
    Coordinate location = cellImage.location;

    Cell cell = state.currentSheet.getRow(location.getRow()).getCell(location.getCol());

    IImageContent image = cellImage.image;

    StyleManagerUtils smu = state.getSmu();
    float ptHeight = cell.getRow().getHeightInPoints();
    if (image.getHeight() != null) {
        ptHeight = smu.fontSizeInPoints(image.getHeight().toString());
    }

    // Get image width
    int endCol = cell.getColumnIndex();
    double lastColWidth = ClientAnchorConversions
            .widthUnits2Millimetres((short) state.currentSheet.getColumnWidth(endCol)) + 2.0;
    double mmWidth = 0.0;
    if (smu.isAbsolute(image.getWidth())) {
        mmWidth = image.getWidth().convertTo(DimensionType.UNITS_MM);
    } else if (smu.isPixels(image.getWidth())) {
        mmWidth = ClientAnchorConversions.pixels2Millimetres(image.getWidth().getMeasure());
    }
    int dx = smu.anchorDxFromMM(mmWidth, lastColWidth);
    // Allow image to span multiple columns
    CellRangeAddress mergedRegion = getMergedRegionBegunBy(state.currentSheet, location.getRow(),
            location.getCol());
    if ((cellImage.spanColumns) || (mergedRegion != null)) {
        log.debug("Image size: ", image.getWidth(), " translates as mmWidth = ", mmWidth);
        if (mmWidth > 0) {
            double mmAccumulatedWidth = 0;
            int endColLimit = cellImage.spanColumns ? 256 : mergedRegion.getLastColumn();
            for (endCol = cell.getColumnIndex(); mmAccumulatedWidth < mmWidth
                    && endCol < endColLimit; ++endCol) {
                lastColWidth = ClientAnchorConversions
                        .widthUnits2Millimetres((short) state.currentSheet.getColumnWidth(endCol)) + 2.0;
                mmAccumulatedWidth += lastColWidth;
                log.debug("lastColWidth = ", lastColWidth, "; mmAccumulatedWidth = ", mmAccumulatedWidth);
            }
            if (mmAccumulatedWidth > mmWidth) {
                mmAccumulatedWidth -= lastColWidth;
                --endCol;
                double mmShort = mmWidth - mmAccumulatedWidth;
                dx = smu.anchorDxFromMM(mmShort, lastColWidth);
            }
        }
        /*
              } else {
                 float widthRatio = (float)(mmWidth / lastColWidth);
                 ptHeight = ptHeight * widthRatio;
        */
    }

    int rowsSpanned = state.findRowsSpanned(cell.getRowIndex(), cell.getColumnIndex());
    float neededRowHeightPoints = ptHeight;

    for (int i = 0; i < rowsSpanned; ++i) {
        int rowIndex = cell.getRowIndex() + 1 + i;
        neededRowHeightPoints -= state.currentSheet.getRow(rowIndex).getHeightInPoints();
    }

    if (neededRowHeightPoints > cell.getRow().getHeightInPoints()) {
        cell.getRow().setHeightInPoints(neededRowHeightPoints);
    }

    // ClientAnchor anchor = wb.getCreationHelper().createClientAnchor();
    ClientAnchor anchor = state.getWb().getCreationHelper().createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setRow1(cell.getRowIndex());
    anchor.setCol2(endCol);
    anchor.setRow2(cell.getRowIndex() + rowsSpanned);
    anchor.setDx2(dx);
    anchor.setDy2(smu.anchorDyFromPoints(ptHeight, cell.getRow().getHeightInPoints()));
    anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE);
    drawing.createPicture(anchor, cellImage.imageIdx);
}