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.CommandUtility.java

License:MIT License

private static void createTieCell(final Cell cell, final Map<String, Object> context,
        final ExpressionEngine engine) {

    @SuppressWarnings("unchecked")
    HashMap<String, TieCell> tieCells = (HashMap<String, TieCell>) context.get("tiecells");

    // if tiecells exists is because tieWebSheetBean.isAdvancedContext() is
    // true/*  www . j  a  v  a 2s  .c  om*/
    if (tieCells != null) {

        if (SaveAttrsUtility.isHasSaveAttr(cell)) {

            String saveAttrList = SaveAttrsUtility.getSaveAttrListFromRow(cell.getRow());

            if (saveAttrList != null) {
                String saveAttr = SaveAttrsUtility.getSaveAttrFromList(cell.getColumnIndex(), saveAttrList);
                if (saveAttr != null) {

                    int index = saveAttr.lastIndexOf('.');
                    if (index > 0) {
                        String strObject = saveAttr.substring(0, index);
                        String strMethod = saveAttr.substring(index + 1);
                        strObject = "${" + strObject + "}";

                        Object object = CommandUtility.evaluate(strObject, context, engine);

                        if (object != null) {
                            TieCell tieCell = CellUtility.getOrAddTieCellInMap(cell, tieCells);
                            tieCell.setContextObject(object);
                            tieCell.setObjectStr(strObject);
                            tieCell.setMethodStr(strMethod);
                        }

                    }

                }
            }

        }

    }
}

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

License:MIT License

/**
 * Gets the anchor size.//from   w w w .ja v  a 2 s .c om
 *
 * @param sheet1
 *            the sheet 1
 * @param fcell
 *            the fcell
 * @param cell
 *            the cell
 * @param anchor
 *            the anchor
 * @return the anchor size
 */
public static AnchorSize getAnchorSize(final Sheet sheet1, final FacesCell fcell, final Cell cell,
        final ClientAnchor anchor) {

    if (!(sheet1 instanceof XSSFSheet)) {
        return null;
    }
    double picWidth = 0.0;
    double picHeight = 0.0;
    int left = anchor.getDx1() / org.apache.poi.util.Units.EMU_PER_PIXEL;
    int top = (int) ((double) anchor.getDy1() / org.apache.poi.util.Units.EMU_PER_PIXEL
            / WebSheetUtility.PICTURE_HEIGHT_ADJUST);
    int right = anchor.getDx2() / org.apache.poi.util.Units.EMU_PER_PIXEL;
    int bottom = (int) ((double) anchor.getDy2() / org.apache.poi.util.Units.EMU_PER_PIXEL
            / WebSheetUtility.PICTURE_HEIGHT_ADJUST);

    double cellWidth = 0.0;
    double cellHeight = 0.0;

    if ((cell != null) && (fcell != null)) {
        for (int col = cell.getColumnIndex(); col < cell.getColumnIndex() + fcell.getColspan(); col++) {
            cellWidth += sheet1.getColumnWidthInPixels(col);
        }
        double lastCellWidth = sheet1.getColumnWidthInPixels(cell.getColumnIndex() + fcell.getColspan() - 1);

        for (int rowIndex = cell.getRowIndex(); rowIndex < cell.getRowIndex()
                + fcell.getRowspan(); rowIndex++) {
            cellHeight += WebSheetUtility.pointsToPixels(sheet1.getRow(rowIndex).getHeightInPoints());
        }
        double lastCellHeight = WebSheetUtility
                .pointsToPixels(sheet1.getRow(cell.getRowIndex() + fcell.getRowspan() - 1).getHeightInPoints());

        picWidth = cellWidth - lastCellWidth + right - left;
        picHeight = cellHeight - lastCellHeight + bottom - top;
    } else {
        for (short col = anchor.getCol1(); col < anchor.getCol2(); col++) {
            picWidth += sheet1.getColumnWidthInPixels(col);
        }
        for (int rowindex = anchor.getRow1(); rowindex < anchor.getRow2(); rowindex++) {
            Row row = sheet1.getRow(rowindex);
            if (row != null) {
                picHeight += WebSheetUtility.pointsToPixels(row.getHeightInPoints());
            }
        }
    }

    return new AnchorSize(left, top, (int) picWidth, (int) picHeight, cellWidth, cellHeight);

}

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

License:MIT License

/**
 * Parses the save attr./*  ww  w.  ja  v  a 2 s .co m*/
 *
 * @param cell
 *            the cell
 * @param saveCommentsMap
 *            the save comments map
 * @return the string
 */
public static String parseSaveAttr(final Cell cell, final Map<String, String> saveCommentsMap) {
    if (cell != null) {
        String key = cell.getSheet().getSheetName() + "!"
                + CellUtility.getCellIndexNumberKey(cell.getColumnIndex(), cell.getRowIndex());
        String saveAttr = null;
        if (saveCommentsMap != null) {
            saveAttr = ParserUtility.getStringBetweenBracket(saveCommentsMap.get(key));
        }
        if ((saveAttr == null) && (cell.getCellTypeEnum() == CellType.STRING)) {
            saveAttr = SaveAttrsUtility.parseSaveAttrString(cell.getStringCellValue());
        }
        if ((saveAttr != null) && (!saveAttr.isEmpty())) {
            return TieConstants.CELL_ADDR_PRE_FIX + cell.getColumnIndex() + "=" + saveAttr + ",";
        }
    }
    return "";
}

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

License:MIT License

/**
 * Checks if is checks for save attr.//from  w  w w. ja  va 2  s  . c o  m
 *
 * @param cell
 *            the cell
 * @param saveAttrs
 *            the save attrs
 * @return true, if is checks for save attr
 */
public static boolean isHasSaveAttr(final Cell cell, final String saveAttrs) {

    if (cell != null) {
        int columnIndex = cell.getColumnIndex();
        String str = TieConstants.CELL_ADDR_PRE_FIX + columnIndex + "=";
        if ((saveAttrs != null) && (saveAttrs.indexOf(str) >= 0)) {
            return true;
        }
    }
    return false;
}

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

License:MIT License

/**
 * Prepare context and attrs for cell.//from w ww.j  av a  2  s. c om
 *
 * @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:org.tiefaces.components.websheet.utility.WebSheetUtility.java

License:MIT License

/**
 * return full name for cell with sheet name and $ format e.g. Sheet1$A$1
 * // www  .  j a  va  2 s .  c  om
 * @param sheet1
 *            sheet
 * @param cell
 *            cell
 * @return String full cell reference name
 */

public static String getFullCellRefName(final Sheet sheet1, final Cell cell) {
    if ((sheet1 != null) && (cell != null)) {
        return sheet1.getSheetName() + "!$" + getExcelColumnName(cell.getColumnIndex()) + "$"
                + (cell.getRowIndex() + 1);
    }
    return null;
}

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

License:MIT License

/**
 * Cell compare to./*ww w .  ja v  a  2  s . c  o m*/
 *
 * @param thisCell
 *            the this cell
 * @param otherCell
 *            the other cell
 * @return the int
 */
public static int cellCompareTo(final Cell thisCell, final Cell otherCell) {
    int r = thisCell.getRowIndex() - otherCell.getRowIndex();
    if (r != 0) {
        return r;
    }

    r = thisCell.getColumnIndex() - otherCell.getColumnIndex();
    if (r != 0) {
        return r;
    }

    return 0;
}

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

License:Open Source License

public Topic getCellTopic(Cell cell, TopicMap tm) throws TopicMapException {
    String cellIdentifier = null;
    switch (CELL_TOPIC_IS_BASED_ON) {
    case CELL_VALUE: {
        cellIdentifier = getCellValueAsString(cell);
        break;//from w w  w.j  a va 2s .c  om
    }
    case CELL_SHEET_AND_LOCATION: {
        Sheet sheet = cell.getSheet();
        String sheetName = sheet.getSheetName();
        cellIdentifier = sheetName + "-" + cell.getColumnIndex() + "-" + cell.getRowIndex();
        break;
    }
    case CELL_LOCATION: {
        cellIdentifier = cell.getColumnIndex() + "-" + cell.getRowIndex();
        break;
    }
    case CELL_HASH: {
        cellIdentifier = Integer.toString(cell.hashCode());
        break;
    }
    }
    if (cellIdentifier != null) {
        String si = EXCEL_CELL_SI_PREFIX + "/" + urlEncode(cellIdentifier);
        Topic cellTopic = getOrCreateTopic(tm, si, cellIdentifier);
        cellTopic.addType(getCellTypeTopic(tm));
        return cellTopic;
    }
    return null;
}

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

License:Open Source License

public Topic getColumnTopic(Cell cell, TopicMap tm) throws TopicMapException {
    Topic topic = getOrCreateTopic(tm,/*from   ww  w.ja v  a2  s . c  o m*/
            EXCEL_COLUMN_SI_PREFIX + "/" + urlEncode(Integer.toString(cell.getColumnIndex())),
            "Excel column " + cell.getColumnIndex());
    topic.addType(getColumnTypeTopic(tm));
    return topic;
}

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

License:Open Source License

public void processRow(Row row, TopicMap tm) {
    Iterator<Cell> cellIterator = row.cellIterator();
    Association a = null;/*from w  w  w.  ja  va  2s  .  c o  m*/
    while (cellIterator.hasNext() && !forceStop()) {
        try {
            Cell cell = cellIterator.next();
            if (getCellValueAsString(cell) != null) {
                Topic player = getCellTopic(cell, tm);
                if (player != null) {
                    if (a == null) {
                        a = tm.createAssociation(getDefaultAssociationTypeTopic(tm));
                    }
                    if (a != null) {
                        String roleSI = rolesPerColumn.get(Integer.toString(cell.getColumnIndex()));
                        if (roleSI != null) {
                            Topic role = tm.getTopic(roleSI);
                            if (role == null)
                                role = getDefaultRoleTopic(cell, tm);
                            a.addPlayer(player, role);
                        }
                    }
                }
            }
        } catch (TopicMapException ex) {
            log(ex);
        } catch (Exception ex) {
            log(ex);
        }
    }
}