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

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

Introduction

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

Prototype

int getColumnIndex();

Source Link

Document

Returns column index of this cell

Usage

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

License:MIT License

/**
 * Setup control attributes.//from  w w w  .j  a va2  s  . c  om
 *
 * @param originRowIndex
 *            the origin row index
 * @param fcell
 *            the fcell
 * @param poiCell
 *            the poi cell
 * @param sheetConfig
 *            the sheet config
 * @param cellAttributesMap
 *            the cell attributes map
 */
public static void setupControlAttributes(final int originRowIndex, final FacesCell fcell, final Cell poiCell,
        final SheetConfiguration sheetConfig, final CellAttributesMap cellAttributesMap) {
    int rowIndex = originRowIndex;
    if (rowIndex < 0) {
        rowIndex = poiCell.getRowIndex();
    }

    String skey = poiCell.getSheet().getSheetName() + "!"
            + CellUtility.getCellIndexNumberKey(poiCell.getColumnIndex(), rowIndex);

    Map<String, String> commentMap = cellAttributesMap.getTemplateCommentMap().get("$$");
    if (commentMap != null) {
        String comment = commentMap.get(skey);
        if (comment != null) {
            CommandUtility.createCellComment(poiCell, comment, sheetConfig.getFinalCommentMap());
        }
    }

    String widgetType = cellAttributesMap.getCellInputType().get(skey);
    if (widgetType != null) {
        fcell.setControl(widgetType.toLowerCase());

        fcell.setInputAttrs(cellAttributesMap.getCellInputAttributes().get(skey));
        fcell.setSelectItemAttrs(cellAttributesMap.getCellSelectItemsAttributes().get(skey));
        fcell.setDatePattern(cellAttributesMap.getCellDatePattern().get(skey));
    }

}

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

License:MIT License

/**
 * Find cell validate attributes.//from   www.  j  a  va2  s. com
 *
 * @param validateMaps
 *            validateMaps.
 * @param originRowIndex
 *             original Row Index from facesRow.           
 * @param cell
 *            cell.
 * @return list.
 */
public static List<CellFormAttributes> findCellValidateAttributes(
        final Map<String, List<CellFormAttributes>> validateMaps, final int originRowIndex, final Cell cell) {
    String key = cell.getSheet().getSheetName() + "!"
            + CellUtility.getCellIndexNumberKey(cell.getColumnIndex(), originRowIndex);

    return validateMaps.get(key);
}

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

License:MIT License

/**
 * return cell value with format./*from  ww w.ja  va  2s  .c om*/
 * 
 * @param poiCell
 *            cell.
 * @param formulaEvaluator
 *            formula evaluator.
 * @param dataFormatter
 *            data formatter.
 * @return cell string value with format.
 */
@SuppressWarnings("deprecation")
public static String getCellValueWithFormat(final Cell poiCell, final FormulaEvaluator formulaEvaluator,
        final DataFormatter dataFormatter) {

    if (poiCell == null) {
        return null;
    }

    String result;
    try {
        CellType cellType = poiCell.getCellTypeEnum();
        if (cellType == CellType.FORMULA) {
            cellType = formulaEvaluator.evaluate(poiCell).getCellTypeEnum();
        }
        if (cellType == CellType.ERROR) {
            result = "";
        } else {
            result = dataFormatter.formatCellValue(poiCell, formulaEvaluator);
        }
    } catch (Exception e) {
        LOG.log(Level.SEVERE,
                "Web Form WebFormHelper getCellValue Error row = " + poiCell.getRowIndex() + " column = "
                        + poiCell.getColumnIndex() + " error = " + e.getLocalizedMessage()
                        + "; Change return result to blank",
                e);
        result = "";
    }

    return result;
}

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

License:MIT License

/**
 * Copy cell./*w ww.  jav  a 2  s .  co m*/
 *
 * @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 ww .j ava  2  s  .  c  o 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 comment anchor./* www  .  j  a  va 2 s. co m*/
 *
 * @param newCell the new cell
 * @param factory the factory
 * @return the client anchor
 */
private static ClientAnchor createCommentAnchor(final Cell newCell, CreationHelper factory) {
    ClientAnchor anchor = factory.createClientAnchor();
    anchor.setCol1(newCell.getColumnIndex());
    anchor.setCol2(newCell.getColumnIndex() + 1);
    anchor.setRow1(newCell.getRowIndex());
    anchor.setRow2(newCell.getRowIndex() + 3);
    return anchor;
}

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

License:MIT License

/**
 * Creates the or insert comment.//  w ww . ja v  a 2  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.tiefaces.components.websheet.utility.CellUtility.java

License:MIT License

/**
 * Find CtShape from vml object. This class use reflection to invoke the
 * protected method in POI.//from  w  w  w .j  a va2  s .c  om
 *
 * @param sourceCell            cell.
 * @param sourceVml            vml.
 * @return ctShape.
 * @throws ReflectiveOperationException the reflective operation exception
 * @throws SecurityException the security exception
 */
@SuppressWarnings("rawtypes")
private static CTShape getCtShapeFromVml(final Cell sourceCell, XSSFVMLDrawing sourceVml)
        throws ReflectiveOperationException {
    Method findshape;
    // int parameter
    Class[] paramInt = new Class[2];
    paramInt[0] = Integer.TYPE;
    paramInt[1] = Integer.TYPE;
    findshape = sourceVml.getClass().getDeclaredMethod("findCommentShape", paramInt);
    findshape.setAccessible(true);
    return (CTShape) findshape.invoke(sourceVml, sourceCell.getRowIndex(), sourceCell.getColumnIndex());
}

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

License:MIT License

/**
 * return cell index number key. e.g. $0$0 for A1 cell.
 * // w  ww .j  a  v  a2  s .  c om
 * @param cell
 *            input cell.
 * @return string.
 */
public static String getCellIndexNumberKey(final Cell cell) {
    if (cell != null) {
        return TieConstants.CELL_ADDR_PRE_FIX + cell.getColumnIndex() + TieConstants.CELL_ADDR_PRE_FIX
                + cell.getRowIndex();
    }
    return null;
}

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

License:MIT License

/**
 * Gets the skey from poi cell.//from  w  w  w . j a va 2 s  . co  m
 *
 * @param poiCell the poi cell
 * @return the skey from poi cell
 */
public static String getSkeyFromPoiCell(final Cell poiCell) {
    return poiCell.getSheet().getSheetName() + "!"
            + CellUtility.getCellIndexNumberKey(poiCell.getColumnIndex(), poiCell.getRowIndex());
}