Search in sources :

Example 1 with Area3DPtg

use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.

the class InternalWorkbook method cloneFilter.

public NameRecord cloneFilter(int filterDbNameIndex, int newSheetIndex) {
    NameRecord origNameRecord = getNameRecord(filterDbNameIndex);
    // copy original formula but adjust 3D refs to the new external sheet index
    int newExtSheetIx = checkExternSheet(newSheetIndex);
    Ptg[] ptgs = origNameRecord.getNameDefinition();
    for (int i = 0; i < ptgs.length; i++) {
        Ptg ptg = ptgs[i];
        if (ptg instanceof Area3DPtg) {
            Area3DPtg a3p = (Area3DPtg) ((OperandPtg) ptg).copy();
            a3p.setExternSheetIndex(newExtSheetIx);
            ptgs[i] = a3p;
        } else if (ptg instanceof Ref3DPtg) {
            Ref3DPtg r3p = (Ref3DPtg) ((OperandPtg) ptg).copy();
            r3p.setExternSheetIndex(newExtSheetIx);
            ptgs[i] = r3p;
        }
    }
    NameRecord newNameRecord = createBuiltInName(NameRecord.BUILTIN_FILTER_DB, newSheetIndex + 1);
    newNameRecord.setNameDefinition(ptgs);
    newNameRecord.setHidden(true);
    return newNameRecord;
}
Also used : OperandPtg(org.apache.poi.ss.formula.ptg.OperandPtg) NameXPtg(org.apache.poi.ss.formula.ptg.NameXPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) OperandPtg(org.apache.poi.ss.formula.ptg.OperandPtg) NameRecord(org.apache.poi.hssf.record.NameRecord) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg)

Example 2 with Area3DPtg

use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.

the class OperationEvaluationContext method getExternalNameXEval.

private ValueEval getExternalNameXEval(ExternalName externName, String workbookName) {
    try {
        // Fetch the workbook this refers to, and the name as defined with that
        WorkbookEvaluator refWorkbookEvaluator = _bookEvaluator.getOtherWorkbookEvaluator(workbookName);
        EvaluationName evaluationName = refWorkbookEvaluator.getName(externName.getName(), externName.getIx() - 1);
        if (evaluationName != null && evaluationName.hasFormula()) {
            if (evaluationName.getNameDefinition().length > 1) {
                throw new RuntimeException("Complex name formulas not supported yet");
            }
            // Need to evaluate the reference in the context of the other book
            OperationEvaluationContext refWorkbookContext = new OperationEvaluationContext(refWorkbookEvaluator, refWorkbookEvaluator.getWorkbook(), -1, -1, -1, _tracker);
            Ptg ptg = evaluationName.getNameDefinition()[0];
            if (ptg instanceof Ref3DPtg) {
                Ref3DPtg ref3D = (Ref3DPtg) ptg;
                return refWorkbookContext.getRef3DEval(ref3D);
            } else if (ptg instanceof Ref3DPxg) {
                Ref3DPxg ref3D = (Ref3DPxg) ptg;
                return refWorkbookContext.getRef3DEval(ref3D);
            } else if (ptg instanceof Area3DPtg) {
                Area3DPtg area3D = (Area3DPtg) ptg;
                return refWorkbookContext.getArea3DEval(area3D);
            } else if (ptg instanceof Area3DPxg) {
                Area3DPxg area3D = (Area3DPxg) ptg;
                return refWorkbookContext.getArea3DEval(area3D);
            }
        }
        return ErrorEval.REF_INVALID;
    } catch (WorkbookNotFoundException wnfe) {
        return ErrorEval.REF_INVALID;
    }
}
Also used : Area3DPxg(org.apache.poi.ss.formula.ptg.Area3DPxg) NameXPtg(org.apache.poi.ss.formula.ptg.NameXPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) Ref3DPxg(org.apache.poi.ss.formula.ptg.Ref3DPxg) WorkbookNotFoundException(org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment.WorkbookNotFoundException) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg)

Example 3 with Area3DPtg

use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.

the class NameRecord method getExternSheetNumber.

/** gets the extern sheet number
	 * @return extern sheet index
	 */
public int getExternSheetNumber() {
    Ptg[] tokens = field_13_name_definition.getTokens();
    if (tokens.length == 0) {
        return 0;
    }
    Ptg ptg = tokens[0];
    if (ptg.getClass() == Area3DPtg.class) {
        return ((Area3DPtg) ptg).getExternSheetIndex();
    }
    if (ptg.getClass() == Ref3DPtg.class) {
        return ((Ref3DPtg) ptg).getExternSheetIndex();
    }
    return 0;
}
Also used : Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg)

Example 4 with Area3DPtg

use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.

the class HSSFSheet method getRepeatingRowsOrColums.

private CellRangeAddress getRepeatingRowsOrColums(boolean rows) {
    NameRecord rec = getBuiltinNameRecord(NameRecord.BUILTIN_PRINT_TITLE);
    if (rec == null) {
        return null;
    }
    Ptg[] nameDefinition = rec.getNameDefinition();
    if (nameDefinition == null) {
        return null;
    }
    int maxRowIndex = SpreadsheetVersion.EXCEL97.getLastRowIndex();
    int maxColIndex = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
    for (Ptg ptg : nameDefinition) {
        if (ptg instanceof Area3DPtg) {
            Area3DPtg areaPtg = (Area3DPtg) ptg;
            if (areaPtg.getFirstColumn() == 0 && areaPtg.getLastColumn() == maxColIndex) {
                if (rows) {
                    return new CellRangeAddress(areaPtg.getFirstRow(), areaPtg.getLastRow(), -1, -1);
                }
            } else if (areaPtg.getFirstRow() == 0 && areaPtg.getLastRow() == maxRowIndex) {
                if (!rows) {
                    return new CellRangeAddress(-1, -1, areaPtg.getFirstColumn(), areaPtg.getLastColumn());
                }
            }
        }
    }
    return null;
}
Also used : Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) UnionPtg(org.apache.poi.ss.formula.ptg.UnionPtg) MemFuncPtg(org.apache.poi.ss.formula.ptg.MemFuncPtg) NameRecord(org.apache.poi.hssf.record.NameRecord) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 5 with Area3DPtg

use of org.apache.poi.ss.formula.ptg.Area3DPtg in project poi by apache.

the class EmbeddedObjectRefSubRecord method readRefPtg.

private static Ptg readRefPtg(byte[] formulaRawBytes) {
    LittleEndianInput in = new LittleEndianInputStream(new ByteArrayInputStream(formulaRawBytes));
    byte ptgSid = in.readByte();
    switch(ptgSid) {
        case AreaPtg.sid:
            return new AreaPtg(in);
        case Area3DPtg.sid:
            return new Area3DPtg(in);
        case RefPtg.sid:
            return new RefPtg(in);
        case Ref3DPtg.sid:
            return new Ref3DPtg(in);
    }
    return null;
}
Also used : LittleEndianInput(org.apache.poi.util.LittleEndianInput) ByteArrayInputStream(java.io.ByteArrayInputStream) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) LittleEndianInputStream(org.apache.poi.util.LittleEndianInputStream) AreaPtg(org.apache.poi.ss.formula.ptg.AreaPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg)

Aggregations

Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)15 Ptg (org.apache.poi.ss.formula.ptg.Ptg)8 NameRecord (org.apache.poi.hssf.record.NameRecord)6 Ref3DPtg (org.apache.poi.ss.formula.ptg.Ref3DPtg)5 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)3 MemFuncPtg (org.apache.poi.ss.formula.ptg.MemFuncPtg)3 UnionPtg (org.apache.poi.ss.formula.ptg.UnionPtg)3 AutoFilterInfoRecord (org.apache.poi.hssf.record.AutoFilterInfoRecord)2 LinkedDataRecord (org.apache.poi.hssf.record.chart.LinkedDataRecord)2 NameXPtg (org.apache.poi.ss.formula.ptg.NameXPtg)2 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 InternalSheet (org.apache.poi.hssf.model.InternalSheet)1 CommonObjectDataSubRecord (org.apache.poi.hssf.record.CommonObjectDataSubRecord)1 FtCblsSubRecord (org.apache.poi.hssf.record.FtCblsSubRecord)1 LbsDataSubRecord (org.apache.poi.hssf.record.LbsDataSubRecord)1 ObjRecord (org.apache.poi.hssf.record.ObjRecord)1