Example usage for org.apache.poi.ss.formula.ptg AddPtg instance

List of usage examples for org.apache.poi.ss.formula.ptg AddPtg instance

Introduction

In this page you can find the example usage for org.apache.poi.ss.formula.ptg AddPtg instance.

Prototype

ValueOperatorPtg instance

To view the source code for org.apache.poi.ss.formula.ptg AddPtg instance.

Click Source Link

Usage

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

License:MIT License

/**
 * Change formula ptg by replace one ref with multiple ref. We require user
 * follow the rule to define dynamic formula. e.g. If cell reference in
 * formula maybe become multiple cells, then should use round brackets
 * around it.//from ww w. jav a2  s .c o  m
 * 
 * Case 1: = (A1) + A2 + A3 Case 2: = SUM((A1)) Case 3: = SUM((A1:A2))
 *
 * @param ptg
 *            the ptg
 * @param originalOperandClass
 *            the original operand class
 * @param rowList
 *            the row list
 * @param ptgs
 *            the ptgs
 * @param position
 *            the position
 * @return the ptg[]
 */
protected static Ptg[] fixupRefRelativeRowOneToMany(final Object ptg, final byte originalOperandClass,
        final List<SerialRow> rowList, final Ptg[] ptgs, final int position) {
    int size = rowList.size();
    Ptg[] newPtg = null;
    // if followedby valueoperator, then change to multiple ptg plus Add
    // e.g. (A1) --> (A1+A2)
    if (isFollowedByValueOperator(ptgs, position)) {
        if (ptg instanceof RefPtgBase) {
            newPtg = new Ptg[size + 1];
            buildDynamicRowForRefPtgBase(ptg, originalOperandClass, rowList, newPtg, false);
            newPtg[rowList.size()] = AddPtg.instance;
        }
    } else {
        // otherwise change to mutiple ptg plus parenth
        // e.g. SUM((A1)) --> SUM((A1),(A2))
        // SUM((A1:B1)) --> SUM((A1:B1),(A2:B2))
        newPtg = new Ptg[(size * 2) - 1];
        if (ptg instanceof RefPtgBase) {
            buildDynamicRowForRefPtgBase(ptg, originalOperandClass, rowList, newPtg, true);
        } else {
            buildDynamicRowForAreaPtgBase(ptg, originalOperandClass, rowList, newPtg);
        }
    }
    return newPtg;
}