Search in sources :

Example 1 with Internal

use of org.apache.poi.util.Internal in project poi by apache.

the class CommentsTable method newComment.

/**
     * Create a new comment located` at cell address
     *
     * @param ref the location to add the comment
     * @return a new CTComment located at ref with default author
     */
@Internal
public CTComment newComment(CellAddress ref) {
    CTComment ct = comments.getCommentList().addNewComment();
    ct.setRef(ref.formatAsString());
    ct.setAuthorId(DEFAULT_AUTHOR_ID);
    if (commentRefs != null) {
        commentRefs.put(ref, ct);
    }
    return ct;
}
Also used : CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) Internal(org.apache.poi.util.Internal)

Example 2 with Internal

use of org.apache.poi.util.Internal in project poi by apache.

the class WorkbookEvaluator method evaluateFormula.

// visibility raised for testing
@Internal
/* package */
ValueEval evaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs) {
    // always init. to non-null just for defensive avoiding NPE
    String dbgIndentStr = "";
    if (dbgEvaluationOutputForNextEval) {
        // first evaluation call when ouput is desired, so iit. this evaluator instance
        dbgEvaluationOutputIndent = 1;
        dbgEvaluationOutputForNextEval = false;
    }
    if (dbgEvaluationOutputIndent > 0) {
        // init. indent string to needed spaces (create as substring vom very long space-only string;
        // limit indendation for deep recursions)
        dbgIndentStr = "                                                                                                    ";
        dbgIndentStr = dbgIndentStr.substring(0, Math.min(dbgIndentStr.length(), dbgEvaluationOutputIndent * 2));
        EVAL_LOG.log(POILogger.WARN, dbgIndentStr + "- evaluateFormula('" + ec.getRefEvaluatorForCurrentSheet().getSheetNameRange() + "'/" + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString() + "): " + Arrays.toString(ptgs).replaceAll("\\Qorg.apache.poi.ss.formula.ptg.\\E", ""));
        dbgEvaluationOutputIndent++;
    }
    Stack<ValueEval> stack = new Stack<ValueEval>();
    for (int i = 0, iSize = ptgs.length; i < iSize; i++) {
        // since we don't know how to handle these yet :(
        Ptg ptg = ptgs[i];
        if (dbgEvaluationOutputIndent > 0) {
            EVAL_LOG.log(POILogger.INFO, dbgIndentStr + "  * ptg " + i + ": " + ptg + ", stack: " + stack);
        }
        if (ptg instanceof AttrPtg) {
            AttrPtg attrPtg = (AttrPtg) ptg;
            if (attrPtg.isSum()) {
                // Excel prefers to encode 'SUM()' as a tAttr token, but this evaluator
                // expects the equivalent function token
                ptg = FuncVarPtg.SUM;
            }
            if (attrPtg.isOptimizedChoose()) {
                ValueEval arg0 = stack.pop();
                int[] jumpTable = attrPtg.getJumpTable();
                int dist;
                int nChoices = jumpTable.length;
                try {
                    int switchIndex = Choose.evaluateFirstArg(arg0, ec.getRowIndex(), ec.getColumnIndex());
                    if (switchIndex < 1 || switchIndex > nChoices) {
                        stack.push(ErrorEval.VALUE_INVALID);
                        // +4 for tFuncFar(CHOOSE)
                        dist = attrPtg.getChooseFuncOffset() + 4;
                    } else {
                        dist = jumpTable[switchIndex - 1];
                    }
                } catch (EvaluationException e) {
                    stack.push(e.getErrorEval());
                    // +4 for tFuncFar(CHOOSE)
                    dist = attrPtg.getChooseFuncOffset() + 4;
                }
                // Encoded dist for tAttrChoose includes size of jump table, but
                // countTokensToBeSkipped() does not (it counts whole tokens).
                // subtract jump table size
                dist -= nChoices * 2 + 2;
                i += countTokensToBeSkipped(ptgs, i, dist);
                continue;
            }
            if (attrPtg.isOptimizedIf()) {
                ValueEval arg0 = stack.pop();
                boolean evaluatedPredicate;
                try {
                    evaluatedPredicate = IfFunc.evaluateFirstArg(arg0, ec.getRowIndex(), ec.getColumnIndex());
                } catch (EvaluationException e) {
                    stack.push(e.getErrorEval());
                    int dist = attrPtg.getData();
                    i += countTokensToBeSkipped(ptgs, i, dist);
                    attrPtg = (AttrPtg) ptgs[i];
                    dist = attrPtg.getData() + 1;
                    i += countTokensToBeSkipped(ptgs, i, dist);
                    continue;
                }
                if (evaluatedPredicate) {
                // nothing to skip - true param follows
                } else {
                    int dist = attrPtg.getData();
                    i += countTokensToBeSkipped(ptgs, i, dist);
                    Ptg nextPtg = ptgs[i + 1];
                    if (ptgs[i] instanceof AttrPtg && nextPtg instanceof FuncVarPtg && // if we really have the IF next or some other FuncVarPtg as third param, e.g. ROW()/COLUMN()!
                    ((FuncVarPtg) nextPtg).getFunctionIndex() == FunctionMetadataRegistry.FUNCTION_INDEX_IF) {
                        // this is an if statement without a false param (as opposed to MissingArgPtg as the false param)
                        i++;
                        stack.push(BoolEval.FALSE);
                    }
                }
                continue;
            }
            if (attrPtg.isSkip()) {
                int dist = attrPtg.getData() + 1;
                i += countTokensToBeSkipped(ptgs, i, dist);
                if (stack.peek() == MissingArgEval.instance) {
                    stack.pop();
                    stack.push(BlankEval.instance);
                }
                continue;
            }
        }
        if (ptg instanceof ControlPtg) {
            // skip Parentheses, Attr, etc
            continue;
        }
        if (ptg instanceof MemFuncPtg || ptg instanceof MemAreaPtg) {
            // can ignore, rest of tokens for this expression are in OK RPN order
            continue;
        }
        if (ptg instanceof MemErrPtg) {
            continue;
        }
        if (ptg instanceof UnionPtg) {
            ValueEval v2 = stack.pop();
            ValueEval v1 = stack.pop();
            stack.push(new RefListEval(v1, v2));
            continue;
        }
        ValueEval opResult;
        if (ptg instanceof OperationPtg) {
            OperationPtg optg = (OperationPtg) ptg;
            int numops = optg.getNumberOfOperands();
            ValueEval[] ops = new ValueEval[numops];
            // storing the ops in reverse order since they are popping
            for (int j = numops - 1; j >= 0; j--) {
                ValueEval p = stack.pop();
                ops[j] = p;
            }
            //                logDebug("invoke " + operation + " (nAgs=" + numops + ")");
            opResult = OperationEvaluatorFactory.evaluate(optg, ops, ec);
        } else {
            opResult = getEvalForPtg(ptg, ec);
        }
        if (opResult == null) {
            throw new RuntimeException("Evaluation result must not be null");
        }
        //            logDebug("push " + opResult);
        stack.push(opResult);
        if (dbgEvaluationOutputIndent > 0) {
            EVAL_LOG.log(POILogger.INFO, dbgIndentStr + "    = " + opResult);
        }
    }
    ValueEval value = stack.pop();
    if (!stack.isEmpty()) {
        throw new IllegalStateException("evaluation stack not empty");
    }
    ValueEval result = dereferenceResult(value, ec.getRowIndex(), ec.getColumnIndex());
    if (dbgEvaluationOutputIndent > 0) {
        EVAL_LOG.log(POILogger.INFO, dbgIndentStr + "finshed eval of " + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString() + ": " + result);
        dbgEvaluationOutputIndent--;
        if (dbgEvaluationOutputIndent == 1) {
            // this evaluation is done, reset indent to stop logging
            dbgEvaluationOutputIndent = -1;
        }
    }
    // if
    return result;
}
Also used : CellReference(org.apache.poi.ss.util.CellReference) Stack(java.util.Stack) Internal(org.apache.poi.util.Internal)

Example 3 with Internal

use of org.apache.poi.util.Internal in project poi by apache.

the class XSLFSlideShow method getSlide.

/**
	 * Returns the low level slide object from
	 *  the supplied slide reference
	 */
@Internal
public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
    PackagePart slidePart = getSlidePart(slide);
    SldDocument slideDoc = SldDocument.Factory.parse(slidePart.getInputStream(), DEFAULT_XML_OPTIONS);
    return slideDoc.getSld();
}
Also used : SldDocument(org.openxmlformats.schemas.presentationml.x2006.main.SldDocument) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) Internal(org.apache.poi.util.Internal)

Example 4 with Internal

use of org.apache.poi.util.Internal in project poi by apache.

the class XSLFSlideShow method getNotes.

/**
	 * Returns the low level notes object for the given
	 *  slide, as found from the supplied slide reference
	 */
@Internal
public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
    PackagePart notesPart = getNodesPart(slide);
    if (notesPart == null)
        return null;
    NotesDocument notesDoc = NotesDocument.Factory.parse(notesPart.getInputStream(), DEFAULT_XML_OPTIONS);
    return notesDoc.getNotes();
}
Also used : PackagePart(org.apache.poi.openxml4j.opc.PackagePart) NotesDocument(org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument) Internal(org.apache.poi.util.Internal)

Example 5 with Internal

use of org.apache.poi.util.Internal in project poi by apache.

the class XSLFSlideShow method getSlideMaster.

/**
	 * Returns the low level slide master object from
	 *  the supplied slide master reference
	 */
@Internal
public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException {
    PackagePart masterPart = getSlideMasterPart(master);
    SldMasterDocument masterDoc = SldMasterDocument.Factory.parse(masterPart.getInputStream(), DEFAULT_XML_OPTIONS);
    return masterDoc.getSldMaster();
}
Also used : PackagePart(org.apache.poi.openxml4j.opc.PackagePart) SldMasterDocument(org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument) Internal(org.apache.poi.util.Internal)

Aggregations

Internal (org.apache.poi.util.Internal)13 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)4 TextLayout (java.awt.font.TextLayout)1 AttributedString (java.text.AttributedString)1 NoSuchElementException (java.util.NoSuchElementException)1 Stack (java.util.Stack)1 HSLFException (org.apache.poi.hslf.exceptions.HSLFException)1 TextPropCollection (org.apache.poi.hslf.model.textproperties.TextPropCollection)1 MainMaster (org.apache.poi.hslf.record.MainMaster)1 TxMasterStyleAtom (org.apache.poi.hslf.record.TxMasterStyleAtom)1 HWPFDocumentCore (org.apache.poi.hwpf.HWPFDocumentCore)1 LFO (org.apache.poi.hwpf.model.LFO)1 ListLevel (org.apache.poi.hwpf.model.ListLevel)1 ListTables (org.apache.poi.hwpf.model.ListTables)1 StyleSheet (org.apache.poi.hwpf.model.StyleSheet)1 ParagraphProperties (org.apache.poi.hwpf.usermodel.ParagraphProperties)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1 PackageRelationshipCollection (org.apache.poi.openxml4j.opc.PackageRelationshipCollection)1 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)1 Cell (org.apache.poi.ss.usermodel.Cell)1