From d20b0f635312b87e400fc07b53fc99a86f47c2de Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Mon, 29 Apr 2002 01:25:28 +0000 Subject: [PATCH] Made Formula Record cough up some info useful for debugging, made functions get written, but they crash excel right now. Areas seem to basically work. I need to investigate further, at first glance, our xls looks the same as Excel's. Have to find out what its doing to make it crash like that. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352551 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/record/FormulaRecord.java | 42 +++++++++++++++++++ .../poi/hssf/record/formula/FunctionPtg.java | 15 +++++-- .../apache/poi/hssf/record/formula/Ptg.java | 17 +++++++- .../apache/poi/hssf/util/RangeAddress.java | 2 + 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/FormulaRecord.java b/src/java/org/apache/poi/hssf/record/FormulaRecord.java index fa0f8ed6d5..db8d0bb0b9 100644 --- a/src/java/org/apache/poi/hssf/record/FormulaRecord.java +++ b/src/java/org/apache/poi/hssf/record/FormulaRecord.java @@ -365,6 +365,9 @@ public class FormulaRecord } return getRecordSize(); } + + + public int getRecordSize() { @@ -504,4 +507,43 @@ public class FormulaRecord } return false; } + + + public String toString() + { + StringBuffer buffer = new StringBuffer(); + if (EXPERIMENTAL_FORMULA_SUPPORT_ENABLED) { + buffer.append("[FORMULA]\n"); + buffer.append(" .row = ") + .append(Integer.toHexString(getRow())).append("\n"); + buffer.append(" .column = ") + .append(Integer.toHexString(getColumn())) + .append("\n"); + buffer.append(" .xf = ") + .append(Integer.toHexString(getXFIndex())).append("\n"); + buffer.append(" .value = ").append(getValue()) + .append("\n"); + buffer.append(" .options = ").append(getOptions()) + .append("\n"); + buffer.append(" .zero = ").append(field_6_zero) + .append("\n"); + buffer.append(" .expressionlength= ").append(getExpressionLength()) + .append("\n"); + buffer.append(" .numptgsinarray = ").append(field_8_parsed_expr.size()) + .append("\n"); + + + for (int k = 0; k < field_8_parsed_expr.size(); k++ ) { + buffer.append("formula ").append(k).append(" ") + .append(((Ptg)field_8_parsed_expr.get(k)).toFormulaString()); + } + + + buffer.append("[/FORMULA]\n"); + } else { + buffer.append(super.toString()); + } + return buffer.toString(); + } + } diff --git a/src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java b/src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java index a1e688b113..1fba83ea34 100644 --- a/src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java @@ -16,7 +16,7 @@ import java.util.List; */ public class FunctionPtg extends OperationPtg { public final static short sid = 0x22; - private final static int SIZE = 2; + private final static int SIZE = 3; private byte field_1_num_args; private byte field_2_fnc_index; @@ -27,6 +27,14 @@ public class FunctionPtg extends OperationPtg { public FunctionPtg() { } + public FunctionPtg(byte[] data, int offset) { + offset++; + field_1_num_args = data[ offset + 0 ]; + field_2_fnc_index = data[offset + 1 ]; + + } + + public FunctionPtg(String pName, byte pNumOperands) { field_1_num_args = pNumOperands; field_2_fnc_index = lookupIndex(pName); @@ -79,8 +87,9 @@ public class FunctionPtg extends OperationPtg { public void writeBytes(byte[] array, int offset) { - array[offset]=field_1_num_args; - array[offset]=field_2_fnc_index; + array[offset+0]=sid; + array[offset+1]=field_1_num_args; + array[offset+2]=field_2_fnc_index; } public int getSize() { diff --git a/src/java/org/apache/poi/hssf/record/formula/Ptg.java b/src/java/org/apache/poi/hssf/record/formula/Ptg.java index 2db64a303d..1c73c3553f 100644 --- a/src/java/org/apache/poi/hssf/record/formula/Ptg.java +++ b/src/java/org/apache/poi/hssf/record/formula/Ptg.java @@ -166,6 +166,10 @@ public abstract class Ptg final int arrayRef = ReferencePtg.sid + 0x40; // excel doesn't really care which one you // write. + final int valueFunc = FunctionPtg.sid + 0x20; //note this only matters for READ + final int arrayFunc = FunctionPtg.sid + 0x40; // excel doesn't really care which one you + // write. + switch (id) { @@ -227,9 +231,18 @@ public abstract class Ptg retval = new ParenthesisPtg(data, offset); break; - case ValueVariableFunctionPtg.sid : - retval = new ValueVariableFunctionPtg(data, offset); + case FunctionPtg.sid : + retval = new FunctionPtg(data, offset); break; + +/* case valueFunc : + retval = new FunctionPtg(data, offset); + break; + + case arrayFunc : + retval = new FunctionPtg(data, offset); + break; + */ case NamePtg.sid : retval = new NamePtg(data, offset); diff --git a/src/java/org/apache/poi/hssf/util/RangeAddress.java b/src/java/org/apache/poi/hssf/util/RangeAddress.java index 3e9289e95c..05d5877d63 100644 --- a/src/java/org/apache/poi/hssf/util/RangeAddress.java +++ b/src/java/org/apache/poi/hssf/util/RangeAddress.java @@ -58,6 +58,8 @@ package org.apache.poi.hssf.util; /** * Title: Range Address

* Description: provides connectivity utilities for ranges

+ * + * * REFERENCE:

* @author IgOr KaTz && EuGeNe BuMaGiN (Tal Moshaiov) (VistaPortal LDT.) * @version 1.0