View | Details | Raw Unified | Return to bug 21444
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/dev/FormulaViewer.java (-3 / +3 lines)
Lines 144-150 Link Here
144
            StringBuffer buf = new StringBuffer();
144
            StringBuffer buf = new StringBuffer();
145
            if (token instanceof ExpPtg) return;
145
            if (token instanceof ExpPtg) return;
146
            buf.append(name=((OperationPtg) token).toFormulaString((SheetReferences)null));
146
            buf.append(name=((OperationPtg) token).toFormulaString((Workbook)null));
147
            buf.append(sep);
147
            buf.append(sep);
148
            switch (token.getPtgClass()) {
148
            switch (token.getPtgClass()) {
149
                case Ptg.CLASS_REF :
149
                case Ptg.CLASS_REF :
Lines 213-219 Link Here
213
        StringBuffer buf = new StringBuffer();
213
        StringBuffer buf = new StringBuffer();
214
           for (int i=0;i<numptgs;i++) {
214
           for (int i=0;i<numptgs;i++) {
215
           token = (Ptg) tokens.get(i);
215
           token = (Ptg) tokens.get(i);
216
            buf.append( token.toFormulaString((SheetReferences)null));
216
            buf.append( token.toFormulaString((Workbook)null));
217
            switch (token.getPtgClass()) {
217
            switch (token.getPtgClass()) {
218
                case Ptg.CLASS_REF :
218
                case Ptg.CLASS_REF :
219
                    buf.append("(R)");
219
                    buf.append("(R)");
Lines 233-239 Link Here
233
    private String composeFormula(FormulaRecord record)
233
    private String composeFormula(FormulaRecord record)
234
    {
234
    {
235
       return  org.apache.poi.hssf.model.FormulaParser.toFormulaString((SheetReferences)null,record.getParsedExpression());
235
       return  org.apache.poi.hssf.model.FormulaParser.toFormulaString((Workbook)null,record.getParsedExpression());
236
    }
236
    }
237
    /**
237
    /**
(-)src/java/org/apache/poi/hssf/model/FormulaParser.java (-44 / +63 lines)
Lines 64-70 Link Here
64
//import PTG's .. since we need everything, import *
64
//import PTG's .. since we need everything, import *
65
import org.apache.poi.hssf.record.formula.*;
65
import org.apache.poi.hssf.record.formula.*;
66
import org.apache.poi.hssf.util.SheetReferences;
67
/**
66
/**
Lines 335-344 Link Here
335
        int numArgs = Arguments();
334
        int numArgs = Arguments();
336
        Match(')');
335
        Match(')');
337
        Ptg functionPtg = getFunction(name,(byte)numArgs);
336
        AbstractFunctionPtg functionPtg = getFunction(name,(byte)numArgs);
338
		tokens.add(functionPtg);
337
		tokens.add(functionPtg);
338
        if (functionPtg.getName().equals("externalflag")) {
339
            tokens.add(new NamePtg(name, this.book));
340
        }
341
339
 		//remove what we just put in
342
 		//remove what we just put in
340
		this.functionTokens.remove(0);
343
		this.functionTokens.remove(0);
341
    }
344
    }
Lines 382-389 Link Here
382
     * @param numArgs
385
     * @param numArgs
383
     * @return Ptg a null is returned if we're in an IF formula, it needs extreme manipulation and is handled in this function
386
     * @return Ptg a null is returned if we're in an IF formula, it needs extreme manipulation and is handled in this function
384
     */
387
     */
385
    private Ptg getFunction(String name,byte numArgs) {
388
    private AbstractFunctionPtg getFunction(String name, byte numArgs) {
386
        Ptg retval = null;
389
        AbstractFunctionPtg retval;
387
        if (name.equals("IF")) {
390
        if (name.equals("IF")) {
388
            retval = new FuncVarPtg(AbstractFunctionPtg.ATTR_NAME, numArgs);
391
            retval = new FuncVarPtg(AbstractFunctionPtg.ATTR_NAME, numArgs);
Lines 795-863 Link Here
795
    /**
798
    /**
796
     * Convience method which takes in a list then passes it to the other toFormulaString
799
     * Convience method which takes in a list then passes it to the other toFormulaString
797
     * signature.
800
     * signature.
798
     * @param lptgs - list of ptgs, can be null
801
     * @param book   workbook for 3D and named references
802
     * @param lptgs  list of Ptg, can be null or empty
803
     * @return a human readable String
799
     */
804
     */
800
    public static String toFormulaString(SheetReferences refs, List lptgs) {
805
    public static String toFormulaString(Workbook book, List lptgs) {
801
        String retval = null;
806
        String retval = null;
802
        if (lptgs == null || lptgs.size() == 0) return "#NAME";
807
        if (lptgs == null || lptgs.size() == 0) return "#NAME";
803
        Ptg[] ptgs = new Ptg[lptgs.size()];
808
        Ptg[] ptgs = new Ptg[lptgs.size()];
804
        ptgs = (Ptg[])lptgs.toArray(ptgs);
809
        ptgs = (Ptg[])lptgs.toArray(ptgs);
805
        retval = toFormulaString(refs, ptgs);
810
        retval = toFormulaString(book, ptgs);
806
        return retval;
811
        return retval;
807
    }
812
    }
808
    /** Static method to convert an array of Ptgs in RPN order
813
    /**
809
     *  to a human readable string format in infix mode
814
     * Static method to convert an array of Ptgs in RPN order
810
     *  @param ptgs - array of ptgs, can be null or empty
815
     * to a human readable string format in infix mode.
816
     * @param book  workbook for named and 3D references
817
     * @param ptgs  array of Ptg, can be null or empty
818
     * @return a human readable String
811
     */
819
     */
812
    public static String toFormulaString(SheetReferences refs, Ptg[] ptgs) {
820
    public static String toFormulaString(Workbook book, Ptg[] ptgs) {
813
        if (ptgs == null || ptgs.length == 0) return "#NAME";
821
        if (ptgs == null || ptgs.length == 0) return "#NAME";
814
        java.util.Stack stack = new java.util.Stack();
822
        java.util.Stack stack = new java.util.Stack();
815
        int numPtgs = ptgs.length;
816
        OperationPtg o;
817
        int numOperands;
818
        String result=null;
819
        String[] operands;
820
        AttrPtg ifptg = null;
823
        AttrPtg ifptg = null;
821
        for (int i=0;i<numPtgs;i++) {
824
822
           // Excel allows to have AttrPtg at position 0 (such as Blanks) which
825
           // Excel allows to have AttrPtg at position 0 (such as Blanks) which
823
           // do not have any operands. Skip them.
826
           // do not have any operands. Skip them.
824
            if (ptgs[i] instanceof OperationPtg && i>0) {
827
        stack.push(ptgs[0].toFormulaString(book));
825
                  o = (OperationPtg) ptgs[i];
826
                  if (o instanceof AttrPtg && ((AttrPtg)o).isOptimizedIf()) {
828
        for (int i = 1; i < ptgs.length; i++) {
827
                        ifptg=(AttrPtg)o;
829
            if (! (ptgs[i] instanceof OperationPtg)) {
828
                  } else {
830
                stack.push(ptgs[i].toFormulaString(book));
831
                continue;
832
            }
829
                      numOperands = o.getNumberOfOperands();
833
            if (ptgs[i] instanceof AttrPtg && ((AttrPtg) ptgs[i]).isOptimizedIf()) {
830
                      operands = new String[numOperands];
834
                ifptg = (AttrPtg) ptgs[i];
835
                continue;
836
            }
831
                      for (int j=0;j<numOperands;j++) {
837
            final OperationPtg o = (OperationPtg) ptgs[i];
832
                          operands[numOperands-j-1] = (String) stack.pop(); //TODO: catch stack underflow and throw parse exception.
838
            final String[] operands = new String[o.getNumberOfOperands()];
839
840
            for (int j = operands.length; j > 0; j--) {
841
                //TODO: catch stack underflow and throw parse exception.
842
                operands[j - 1] = (String) stack.pop();
833
                      }
843
                      }
834
                      if ( (o instanceof AbstractFunctionPtg) &&
844
            stack.push(o.toFormulaString(operands));
835
                            ((AbstractFunctionPtg)o).getName().equals("specialflag") &&
845
            if (!(o instanceof AbstractFunctionPtg)) continue;
836
                            ifptg != null
846
837
                            ) {
847
            final AbstractFunctionPtg f = (AbstractFunctionPtg) o;
848
            final String fname = f.getName();
849
            if (fname == null) continue;
850
851
            if ((ifptg != null) && (fname.equals("specialflag"))) {
838
                             // this special case will be way different.
852
                             // this special case will be way different.
839
                             result = ifptg.toFormulaString(
853
                stack.push(ifptg.toFormulaString(new String[]{(String) stack.pop()}));
840
                                  new String[] {(o.toFormulaString(operands))}
841
                                                           );
842
                             ifptg = null;
854
                             ifptg = null;
843
                      } else {
855
                continue;
844
                        result = o.toFormulaString(operands);
845
                      }
856
                      }
846
                      stack.push(result);
857
            if (fname.equals("externalflag")) {
847
                  }
858
                final String top = (String) stack.pop();
848
859
                final int paren = top.indexOf('(');
849
            } else {
860
                final int comma = top.indexOf(',');
850
                stack.push(ptgs[i].toFormulaString(refs));
861
                if (comma == -1) {
862
                    final int rparen = top.indexOf(')');
863
                    stack.push(top.substring(paren + 1, rparen) + "()");
864
                }
865
                else {
866
                    stack.push(top.substring(paren + 1, comma) + '(' +
867
                               top.substring(comma + 1));
851
            }
868
            }
852
        }
869
        }
853
        return (String) stack.pop(); //TODO: catch stack underflow and throw parse exception.
854
    }
870
    }
871
        // TODO: catch stack underflow and throw parse exception.
872
        return (String) stack.pop();
873
    }
874
875
855
    /** Create a tree representation of the RPN token array
876
    /** Create a tree representation of the RPN token array
856
     *used to run the class(RVA) change algo
877
     *used to run the class(RVA) change algo
857
     */
878
     */
Lines 890-900 Link Here
890
     *   Useful for testing
911
     *   Useful for testing
891
     */
912
     */
892
    public String toString() {
913
    public String toString() {
893
        SheetReferences refs = null;
894
        if (book!=null)  book.getSheetReferences();
895
        StringBuffer buf = new StringBuffer();
914
        StringBuffer buf = new StringBuffer();
896
           for (int i=0;i<tokens.size();i++) {
915
           for (int i=0;i<tokens.size();i++) {
897
            buf.append( ( (Ptg)tokens.get(i)).toFormulaString(refs));
916
            buf.append( ( (Ptg)tokens.get(i)).toFormulaString(book));
898
            buf.append(' ');
917
            buf.append(' ');
899
        }
918
        }
900
        return buf.toString();
919
        return buf.toString();
(-)src/java/org/apache/poi/hssf/record/NameRecord.java (-10 / +64 lines)
Lines 55-76 Link Here
55
package org.apache.poi.hssf.record;
55
package org.apache.poi.hssf.record;
56
56
import java.util.List;
57
import java.util.List;
57
import java.util.Stack;
58
import java.util.Stack;
58
59
import org.apache.poi.hssf.model.Workbook;
59
import org.apache.poi.hssf.record.formula.Area3DPtg;
60
import org.apache.poi.hssf.record.formula.Area3DPtg;
60
import org.apache.poi.hssf.record.formula.Ptg;
61
import org.apache.poi.hssf.record.formula.Ptg;
61
import org.apache.poi.hssf.record.formula.Ref3DPtg;
62
import org.apache.poi.hssf.record.formula.Ref3DPtg;
62
import org.apache.poi.hssf.util.RangeAddress;
63
import org.apache.poi.hssf.util.RangeAddress;
63
import org.apache.poi.hssf.util.SheetReferences;
64
import org.apache.poi.util.HexDump;
64
import org.apache.poi.util.HexDump;
65
import org.apache.poi.util.LittleEndian;
65
import org.apache.poi.util.LittleEndian;
66
import org.apache.poi.util.StringUtil;
66
import org.apache.poi.util.StringUtil;
67
/**
67
/**
68
 * Title:        Name Record (aka Named Range) <P>
68
 * Title:        Name Record (aka Named Range) <P>
69
 * Description:  Defines a named range within a workbook. <P>
69
 * Description:  Defines a named range within a workbook. <P>
70
 * REFERENCE:  <P>
70
 * REFERENCE:  <P>
71
 * @author Libin Roman (Vista Portal LDT. Developer)
71
 * @author Libin Roman (Vista Portal LDT. Developer)
72
 * @author  Sergei Kozello (sergeikozello at mail.ru)
72
 * @author  Sergei Kozello (sergeikozello at mail.ru)
73
 * @author Glen Stampoultzis (glens at apache.org)
73
 * @author Glen Stampoultzis (glens at apache.org)
Lines 127-132 Link Here
127
	 */
127
	 */
128
	public final static byte  BUILTIN_SHEET_TITLE           = (byte)12;
128
	public final static byte  BUILTIN_SHEET_TITLE           = (byte)12;
129
    public static final short OPT_HIDDEN_NAME =   (short) 0x0001;
130
    public static final short OPT_FUNCTION_NAME = (short) 0x0002;
131
    public static final short OPT_COMMAND_NAME =  (short) 0x0004;
132
    public static final short OPT_MACRO =         (short) 0x0008;
133
    public static final short OPT_COMPLEX =       (short) 0x0010;
134
    public static final short OPT_BUILTIN =       (short) 0x0020;
135
    public static final short OPT_BINDATA =       (short) 0x1000;
136
129
    private short             field_1_option_flag;
137
    private short             field_1_option_flag;
130
    private byte              field_2_keyboard_shortcut;
138
    private byte              field_2_keyboard_shortcut;
Lines 192-198 Link Here
192
	{
200
	{
193
	    this();
201
	    this();
194
	    this.field_12_builtIn_name = builtin;
202
	    this.field_12_builtIn_name = builtin;
195
	    this.setOptionFlag((short)(this.getOptionFlag() | (short)0x20));
203
        this.setOptionFlag((short)(this.getOptionFlag() | OPT_BUILTIN));
196
	    this.setNameTextLength((byte)1);
204
	    this.setNameTextLength((byte)1);
197
	    this.setEqualsToIndexToSheet(index); //the extern sheets are set through references
205
	    this.setEqualsToIndexToSheet(index); //the extern sheets are set through references
Lines 252-258 Link Here
252
	/**
260
	/**
253
	 * Convenience method to retrieve the index the name refers to.
261
	 * Convenience method to retrieve the index the name refers to.
254
	 * @see getEqualsToIndexToSheet()
262
     * @see #getEqualsToIndexToSheet()
255
	 * @return short
263
	 * @return short
256
	 */
264
	 */
257
	public short getIndexToSheet() {
265
	public short getIndexToSheet() {
Lines 346-351 Link Here
346
        return field_1_option_flag;
354
        return field_1_option_flag;
347
    }
355
    }
356
    /**
357
     * @return function group
358
     * @see FnGroupCountRecord
359
     */
360
    public byte getFnGroup() {
361
        int masked = field_1_option_flag & 0x0fc0;
362
        return (byte) (masked >> 4);
363
    }
364
348
    /** returns the keyboard shortcut
365
    /** returns the keyboard shortcut
349
     * @return keyboard shortcut
366
     * @return keyboard shortcut
350
     */
367
     */
Lines 409-422 Link Here
409
        return field_11_compressed_unicode_flag;
426
        return field_11_compressed_unicode_flag;
410
    }
427
    }
428
    /**
429
     * @return true if name is hidden
430
     */
431
    public boolean isHiddenName() {
432
        return (field_1_option_flag & OPT_HIDDEN_NAME) != 0;
433
    }
434
435
    /**
436
     * @return true if name is a function
437
     */
438
    public boolean isFunctionName() {
439
        return (field_1_option_flag & OPT_FUNCTION_NAME) != 0;
440
    }
441
442
    /**
443
     * @return true if name is a command
444
     */
445
    public boolean isCommandName() {
446
        return (field_1_option_flag & OPT_COMMAND_NAME) != 0;
447
    }
448
449
    /**
450
     * @return true if function macro or command macro
451
     */
452
    public boolean isMacro() {
453
        return (field_1_option_flag & OPT_MACRO) != 0;
454
    }
455
456
    /**
457
     * @return true if array formula or user defined
458
     */
459
    public boolean isComplexFunction() {
460
        return (field_1_option_flag & OPT_COMPLEX) != 0;
461
    }
462
463
411
	/**Convenience Function to determine if the name is a built-in name
464
	/**Convenience Function to determine if the name is a built-in name
412
	 */
465
	 */
413
	public boolean isBuiltInName()
466
	public boolean isBuiltInName()
414
	{
467
	{
415
	    return ((this.getOptionFlag() & (short)0x20) != 0);
468
        return ((this.getOptionFlag() & OPT_BUILTIN) != 0);
416
	}
469
	}
470
417
	/** gets the name
471
	/** gets the name
418
	 * @return name
472
	 * @return name
419
	 */
473
	 */
Lines 511-517 Link Here
511
        data[18 + offset] = getCompressedUnicodeFlag();
565
        data[18 + offset] = getCompressedUnicodeFlag();
512
        /* temp: gjs
566
        /* temp: gjs
513
        if ( ( field_1_option_flag & (short) 0x20 ) != 0 )
567
           if (isBuiltInName())
514
        {
568
        {
515
            LittleEndian.putShort( data, 2 + offset, (short) ( 16 + field_13_raw_name_definition.length ) );
569
            LittleEndian.putShort( data, 2 + offset, (short) ( 16 + field_13_raw_name_definition.length ) );
Lines 647-662 Link Here
647
    /** gets the reference , the area only (range)
701
    /** gets the reference , the area only (range)
648
     * @return area reference
702
     * @return area reference
649
     */
703
     */
650
    public String getAreaReference(SheetReferences refs){
704
    public String getAreaReference(Workbook book){
651
        if (field_13_name_definition == null) return "#REF!";
705
        if (field_13_name_definition == null) return "#REF!";
652
        Ptg ptg = (Ptg) field_13_name_definition.peek();
706
        Ptg ptg = (Ptg) field_13_name_definition.peek();
653
        String result = "";
707
        String result = "";
654
        if (ptg.getClass() == Area3DPtg.class){
708
        if (ptg.getClass() == Area3DPtg.class){
655
            result = ptg.toFormulaString(refs);
709
            result = ptg.toFormulaString(book);
656
        } else if (ptg.getClass() == Ref3DPtg.class){
710
        } else if (ptg.getClass() == Ref3DPtg.class){
657
            result = ptg.toFormulaString(refs);
711
            result = ptg.toFormulaString(book);
658
        }
712
        }
659
        return result;
713
        return result;
Lines 727-733 Link Here
727
        /*
781
        /*
728
        temp: gjs
782
        temp: gjs
729
        if ( ( field_1_option_flag & (short)0x20 ) != 0 ) {
783
          if (isBuiltInName()) {
730
            // DEBUG
784
            // DEBUG
731
            // System.out.println( "Built-in name" );
785
            // System.out.println( "Built-in name" );
(-)src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java (-5 / +7 lines)
Lines 53-62 Link Here
53
 */
53
 */
54
package org.apache.poi.hssf.record.formula;
54
package org.apache.poi.hssf.record.formula;
55
import org.apache.poi.hssf.model.Workbook;
55
import org.apache.poi.util.BinaryTree;
56
import org.apache.poi.util.BinaryTree;
56
import org.apache.poi.hssf.util.SheetReferences;
57
import java.util.Stack;
58
/**
57
/**
59
 * This class provides the base functionality for Excel sheet functions
58
 * This class provides the base functionality for Excel sheet functions
Lines 69-75 Link Here
69
	//constant used allow a ptgAttr to be mapped properly for its functionPtg
68
	//constant used allow a ptgAttr to be mapped properly for its functionPtg
70
	public static final String ATTR_NAME = "specialflag";
69
	public static final String ATTR_NAME = "specialflag";
71
70
    public static final short INDEX_EXTERNAL = 255;
72
    private static BinaryTree map = produceHash();
71
    private static BinaryTree map = produceHash();
73
    protected static Object[][] functionData = produceFunctionData();
72
    protected static Object[][] functionData = produceFunctionData();
Lines 104-110 Link Here
104
        return lookupName(field_2_fnc_index);
103
        return lookupName(field_2_fnc_index);
105
    }
104
    }
106
    public String toFormulaString(SheetReferences refs) {
105
    public String toFormulaString(Workbook book) {
107
        return getName();
106
        return getName();
108
    }
107
    }
Lines 140-146 Link Here
140
    }
139
    }
141
    protected short lookupIndex(String name) {
140
    protected short lookupIndex(String name) {
142
        return (short)((Integer)map.getKeyForValue(name)).intValue();
141
        Integer index = (Integer) map.getKeyForValue(name);
142
        if (index != null) return index.shortValue();
143
        return INDEX_EXTERNAL;
143
    }
144
    }
144
    /**
145
    /**
Lines 389-394 Link Here
389
        dmap.put(new Integer(252),"FREQUENCY");
390
        dmap.put(new Integer(252),"FREQUENCY");
390
        dmap.put(new Integer(253),"ADDTOOLBAR");
391
        dmap.put(new Integer(253),"ADDTOOLBAR");
391
        dmap.put(new Integer(254),"DELETETOOLBAR");
392
        dmap.put(new Integer(254),"DELETETOOLBAR");
393
        dmap.put(new Integer(255),"externalflag");
392
        dmap.put(new Integer(256),"RESETTOOLBAR");
394
        dmap.put(new Integer(256),"RESETTOOLBAR");
393
        dmap.put(new Integer(257),"EVALUATE");
395
        dmap.put(new Integer(257),"EVALUATE");
394
        dmap.put(new Integer(258),"GETTOOLBAR");
396
        dmap.put(new Integer(258),"GETTOOLBAR");
(-)src/java/org/apache/poi/hssf/record/formula/AddPtg.java (-2 / +3 lines)
Lines 60-68 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import java.util.List;
62
import java.util.List;
63
import org.apache.poi.hssf.util.SheetReferences;
63
import org.apache.poi.hssf.model.Workbook;
64
64
/**
65
/**
65
 * Addition operator PTG the "+" binomial operator.  If you need more
66
 * Addition operator PTG the "+" binomial operator.  If you need more
Lines 113-119 Link Here
113
    }
113
    }
114
    /** Implementation of method from Ptg */
114
    /** Implementation of method from Ptg */
115
    public String toFormulaString(SheetReferences refs)
115
    public String toFormulaString(Workbook book)
116
    {
116
    {
117
        return "+";
117
        return "+";
118
    }
118
    }
(-)src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java (-4 / +4 lines)
Line 236 Link Here
236
	/**
236
	/**
237
	 * sets the first row to relative or not
237
	 * sets the first row to relative or not
238
	 * @param isRelative or not.
238
	 * @param rel isRelative or not.
239
	 */
239
	 */
240
	public void setFirstRowRelative( boolean rel )
240
	public void setFirstRowRelative( boolean rel )
241
	{
241
	{
Lines 253-259 Link Here
253
	/**
253
	/**
254
	 * set whether the last row is relative or not
254
	 * set whether the last row is relative or not
255
	 * @param last row relative
255
	 * @param rel last row relative
256
	 */
256
	 */
257
	public void setLastRowRelative( boolean rel )
257
	public void setLastRowRelative( boolean rel )
258
	{
258
	{
Lines 291-299 Link Here
291
	}
291
	}
292
	public String toFormulaString( SheetReferences refs )
292
	public String toFormulaString( Workbook book )
293
	{
293
	{
294
		StringBuffer retval = new StringBuffer();
294
		StringBuffer retval = new StringBuffer();
295
                SheetReferences refs = book.getSheetReferences();
295
		if ( refs != null )
296
		if ( refs != null )
296
		{
297
		{
297
			retval.append( refs.getSheetName( this.field_1_index_extern_sheet ) );
298
			retval.append( refs.getSheetName( this.field_1_index_extern_sheet ) );
Lines 351-354 Link Here
351
}
352
}
352
(-)src/java/org/apache/poi/hssf/record/formula/AreaPtg.java (-7 / +6 lines)
Lines 60-71 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import org.apache.poi.util.LittleEndian;
62
import org.apache.poi.hssf.model.Workbook;
63
import org.apache.poi.util.BitField;
64
65
import org.apache.poi.hssf.util.AreaReference;
63
import org.apache.poi.hssf.util.AreaReference;
66
import org.apache.poi.hssf.util.CellReference;
64
import org.apache.poi.hssf.util.CellReference;
67
import org.apache.poi.hssf.util.SheetReferences;
65
import org.apache.poi.util.BitField;
66
import org.apache.poi.util.LittleEndian;
68
/**
67
/**
69
 * Specifies a rectangular area of cells A1:A4 for instance.
68
 * Specifies a rectangular area of cells A1:A4 for instance.
Lines 171-177 Link Here
171
    }
170
    }
172
    /**
171
    /**
173
     * @param last row number in the area
172
     * @param row last row number in the area
174
     */
173
     */
175
    public void setLastRow(short row)
174
    public void setLastRow(short row)
176
    {
175
    {
Lines 267-273 Link Here
267
    /**
266
    /**
268
     * set whether the last row is relative or not
267
     * set whether the last row is relative or not
269
     * @param last row relative
268
     * @param rel last row relative
270
     */
269
     */
271
    public void setLastRowRelative(boolean rel) {
270
    public void setLastRowRelative(boolean rel) {
272
        field_4_last_column=rowRelative.setShortBoolean(field_4_last_column,rel);
271
        field_4_last_column=rowRelative.setShortBoolean(field_4_last_column,rel);
Lines 305-311 Link Here
305
        field_4_last_column = column;
304
        field_4_last_column = column;
306
    }
305
    }
307
    public String toFormulaString(SheetReferences refs)
306
    public String toFormulaString(Workbook book)
308
    {
307
    {
309
         return (new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative())).toString() + ":" +
308
         return (new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative())).toString() + ":" +
310
                (new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative())).toString();
309
                (new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative())).toString();
(-)src/java/org/apache/poi/hssf/record/formula/AttrPtg.java (-7 / +6 lines)
Lines 60-69 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import org.apache.poi.hssf.util.SheetReferences;
62
import org.apache.poi.hssf.model.Workbook;
63
64
import org.apache.poi.util.LittleEndian;
65
import org.apache.poi.util.BitField;
63
import org.apache.poi.util.BitField;
64
import org.apache.poi.util.LittleEndian;
66
import java.util.List;
65
import java.util.List;
Lines 207-217 Link Here
207
        if(space.isSet(field_1_options)) {
206
        if(space.isSet(field_1_options)) {
208
            return operands[ 0 ];
207
            return operands[ 0 ];
209
        } else if (optiIf.isSet(field_1_options)) {
208
        } else if (optiIf.isSet(field_1_options)) {
210
            return toFormulaString((SheetReferences)null) + "(" + operands[ 0 ]             +")";
209
            return toFormulaString((Workbook)null) + "(" + operands[ 0 ]             +")";
211
        } else if (optGoto.isSet(field_1_options)) {
210
        } else if (optGoto.isSet(field_1_options)) {
212
            return toFormulaString((SheetReferences)null) + operands[0];   //goto isn't a real formula element should not show up
211
            return toFormulaString((Workbook)null) + operands[0];   //goto isn't a real formula element should not show up
213
        } else {
212
        } else {
214
            return toFormulaString((SheetReferences)null) + "(" + operands[ 0 ] + ")";
213
            return toFormulaString((Workbook)null) + "(" + operands[ 0 ] + ")";
215
        }
214
        }
216
    }
215
    }
Lines 226-232 Link Here
226
        return -1;
225
        return -1;
227
    }
226
    }
228
   public String toFormulaString(SheetReferences refs) {
227
   public String toFormulaString(Workbook book) {
229
      if(semiVolatile.isSet(field_1_options)) {
228
      if(semiVolatile.isSet(field_1_options)) {
230
        return "ATTR(semiVolatile)";
229
        return "ATTR(semiVolatile)";
231
      }
230
      }
(-)src/java/org/apache/poi/hssf/record/formula/BoolPtg.java (-2 / +2 lines)
Lines 59-66 Link Here
59
 */
59
 */
60
package org.apache.poi.hssf.record.formula;
60
package org.apache.poi.hssf.record.formula;
61
import org.apache.poi.hssf.model.Workbook;
61
import org.apache.poi.util.LittleEndian;
62
import org.apache.poi.util.LittleEndian;
62
import org.apache.poi.hssf.util.SheetReferences;
63
/**
63
/**
64
 * Boolean (boolean)
64
 * Boolean (boolean)
Lines 114-120 Link Here
114
        return SIZE;
114
        return SIZE;
115
    }
115
    }
116
    public String toFormulaString(SheetReferences refs)
116
    public String toFormulaString(Workbook book)
117
    {
117
    {
118
        return field_1_value ? "TRUE" : "FALSE";
118
        return field_1_value ? "TRUE" : "FALSE";
119
    }
119
    }
(-)src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java (-2 / +2 lines)
Lines 62-68 Link Here
62
import java.util.List;
62
import java.util.List;
63
import org.apache.poi.hssf.util.SheetReferences;
63
import org.apache.poi.hssf.model.Workbook;
64
/**
64
/**
65
 *
65
 *
Lines 108-114 Link Here
108
        return 2;
108
        return 2;
109
    }
109
    }
110
    public String toFormulaString(SheetReferences refs)
110
    public String toFormulaString(Workbook book)
111
    {
111
    {
112
        return CONCAT;
112
        return CONCAT;
113
    }
113
    }
(-)src/java/org/apache/poi/hssf/record/formula/DividePtg.java (-3 / +3 lines)
Lines 62-68 Link Here
62
import java.util.List;
62
import java.util.List;
63
import org.apache.poi.hssf.util.SheetReferences;
63
import org.apache.poi.hssf.model.Workbook;
64
/**
64
/**
65
 * This PTG implements the standard binomial divide "/"
65
 * This PTG implements the standard binomial divide "/"
Lines 108-114 Link Here
108
        return 2;
108
        return 2;
109
    }
109
    }
110
    public String toFormulaString(SheetReferences refs)
110
    public String toFormulaString(Workbook book)
111
    {
111
    {
112
        return "/";
112
        return "/";
113
    }
113
    }
Lines 117-123 Link Here
117
        StringBuffer buffer = new StringBuffer();
117
        StringBuffer buffer = new StringBuffer();
118
        buffer.append(operands[ 0 ]);
118
        buffer.append(operands[ 0 ]);
119
        buffer.append(toFormulaString((SheetReferences)null));
119
        buffer.append(toFormulaString((Workbook)null));
120
        buffer.append(operands[ 1 ]);
120
        buffer.append(operands[ 1 ]);
121
        return buffer.toString();
121
        return buffer.toString();
122
    }
122
    }
(-)src/java/org/apache/poi/hssf/record/formula/EqualPtg.java (-3 / +3 lines)
Lines 62-68 Link Here
62
import java.util.List;
62
import java.util.List;
63
import org.apache.poi.hssf.util.SheetReferences;
63
import org.apache.poi.hssf.model.Workbook;
64
/**
64
/**
65
 *
65
 *
Lines 107-113 Link Here
107
        return 2;
107
        return 2;
108
    }
108
    }
109
    public String toFormulaString(SheetReferences refs)
109
    public String toFormulaString(Workbook book)
110
    {
110
    {
111
        return "=";
111
        return "=";
112
    }
112
    }
Lines 117-123 Link Here
117
        buffer.append(operands[ 0 ]);
117
        buffer.append(operands[ 0 ]);
118
        buffer.append(toFormulaString((SheetReferences)null));
118
        buffer.append(toFormulaString((Workbook)null));
119
        buffer.append(operands[ 1 ]);
119
        buffer.append(operands[ 1 ]);
120
        return buffer.toString();
120
        return buffer.toString();
121
    }
121
    }
(-)src/java/org/apache/poi/hssf/record/formula/ExpPtg.java (-2 / +3 lines)
Lines 60-66 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import org.apache.poi.hssf.util.SheetReferences;
62
import org.apache.poi.hssf.model.Workbook;
63
/**
63
/**
64
 *
64
 *
Lines 102-108 Link Here
102
        return SIZE;
102
        return SIZE;
103
    }
103
    }
104
    public String toFormulaString(SheetReferences refs)
104
105
    public String toFormulaString(Workbook book)
105
    {
106
    {
106
        return "NO IDEA SHARED FORMULA EXP PTG";
107
        return "NO IDEA SHARED FORMULA EXP PTG";
107
    }
108
    }
(-)src/java/org/apache/poi/hssf/record/formula/GreaterEqualPtg.java (-4 / +3 lines)
Lines 53-60 Link Here
53
 */
53
 */
54
package org.apache.poi.hssf.record.formula;
54
package org.apache.poi.hssf.record.formula;
55
55
import org.apache.poi.hssf.model.Workbook;
56
import org.apache.poi.hssf.util.SheetReferences;
57
/**
56
/**
58
 * PTG class to implement greater or equal to
57
 * PTG class to implement greater or equal to
Lines 98-104 Link Here
98
        return 2;
97
        return 2;
99
    }
98
    }
100
    public String toFormulaString(SheetReferences refs)
99
    public String toFormulaString(Workbook book)
101
    {
100
    {
102
        return ">=";
101
        return ">=";
103
    }
102
    }
Lines 108-114 Link Here
108
        buffer.append(operands[ 0 ]);
107
        buffer.append(operands[ 0 ]);
109
        buffer.append(toFormulaString((SheetReferences)null));
108
        buffer.append(toFormulaString((Workbook)null));
110
        buffer.append(operands[ 1 ]);
109
        buffer.append(operands[ 1 ]);
111
        return buffer.toString();
110
        return buffer.toString();
112
    }
111
    }
(-)src/java/org/apache/poi/hssf/record/formula/GreaterThanPtg.java (-5 / +3 lines)
Lines 61-67 Link Here
61
import java.util.List;
61
import java.util.List;
62
import org.apache.poi.hssf.util.SheetReferences;
62
import org.apache.poi.hssf.model.Workbook;
63
/**
63
/**
64
 * Greater than operator PTG ">"
64
 * Greater than operator PTG ">"
Lines 131-139 Link Here
131
    /**
131
    /**
132
     * Implementation of method from Ptg
132
     * Implementation of method from Ptg
133
     * @param refs the Sheet References
133
     * @param book the Workbook
134
     */
134
     */
135
    public String toFormulaString(SheetReferences refs)
135
    public String toFormulaString(Workbook book)
136
    {
136
    {
137
        return this.GREATERTHAN;
137
        return this.GREATERTHAN;
138
    }
138
    }
Lines 171-175 Link Here
171
        return new GreaterThanPtg();
171
        return new GreaterThanPtg();
172
    }
172
    }
173
}
173
}
174
175
(-)src/java/org/apache/poi/hssf/record/formula/IntPtg.java (-4 / +4 lines)
Lines 60-71 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import org.apache.poi.hssf.model.Workbook;
62
import org.apache.poi.util.LittleEndian;
63
import org.apache.poi.util.LittleEndian;
63
import org.apache.poi.hssf.util.SheetReferences;
64
/**
64
/**
65
 * Integer (short intger)
65
 * Integer (short integer).
66
 * Stores a (java) short value in a formula
66
 * Stores a (java) short value in a formula.
67
 * @author  Andrew C. Oliver (acoliver at apache dot org)
67
 * @author  Andrew C. Oliver (acoliver at apache dot org)
68
 * @author Jason Height (jheight at chariot dot net dot au)
68
 * @author Jason Height (jheight at chariot dot net dot au)
69
 */
69
 */
Lines 116-122 Link Here
116
        return SIZE;
116
        return SIZE;
117
    }
117
    }
118
    public String toFormulaString(SheetReferences refs)
118
    public String toFormulaString(Workbook book)
119
    {
119
    {
120
        return "" + getValue();
120
        return "" + getValue();
121
    }
121
    }
(-)src/java/org/apache/poi/hssf/record/formula/LessEqualPtg.java (-3 / +3 lines)
Lines 53-59 Link Here
53
 */
53
 */
54
package org.apache.poi.hssf.record.formula;
54
package org.apache.poi.hssf.record.formula;
55
import org.apache.poi.hssf.util.SheetReferences;
55
import org.apache.poi.hssf.model.Workbook;
56
/**
56
/**
Lines 99-105 Link Here
99
		  return 2;
99
		  return 2;
100
	 }
100
	 }
101
	 public String toFormulaString(SheetReferences refs)
101
	 public String toFormulaString(Workbook book)
102
	 {
102
	 {
103
		  return "<=";
103
		  return "<=";
104
	 }
104
	 }
Lines 109-115 Link Here
109
		  buffer.append(operands[ 0 ]);
109
		  buffer.append(operands[ 0 ]);
110
		  buffer.append(toFormulaString((SheetReferences)null));
110
		  buffer.append(toFormulaString((Workbook)null));
111
		  buffer.append(operands[ 1 ]);
111
		  buffer.append(operands[ 1 ]);
112
		  return buffer.toString();
112
		  return buffer.toString();
113
	 }
113
	 }
(-)src/java/org/apache/poi/hssf/record/formula/LessThanPtg.java (-6 / +3 lines)
Lines 63-69 Link Here
63
import java.util.List;
63
import java.util.List;
64
//POI
64
//POI
65
import org.apache.poi.hssf.util.SheetReferences;
65
import org.apache.poi.hssf.model.Workbook;
66
/**
66
/**
67
 * Less than operator PTG "<". The SID is taken from the
67
 * Less than operator PTG "<". The SID is taken from the
Lines 140-148 Link Here
140
    /**
140
    /**
141
     * Implementation of method from Ptg
141
     * Implementation of method from Ptg
142
     * @param refs the Sheet References
142
     * @param book the Workbook
143
     */
143
     */
144
    public String toFormulaString(SheetReferences refs)
144
    public String toFormulaString(Workbook book)
145
    {
145
    {
146
        return this.LESSTHAN;
146
        return this.LESSTHAN;
147
    }
147
    }
Lines 180-185 Link Here
180
    }
180
    }
181
}
181
}
182
183
184
(-)src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java (-2 / +2 lines)
Lines 60-67 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import org.apache.poi.hssf.model.Workbook;
62
import org.apache.poi.util.LittleEndian;
63
import org.apache.poi.util.LittleEndian;
63
import org.apache.poi.hssf.util.SheetReferences;
64
/**
64
/**
65
 *
65
 *
Lines 118-124 Link Here
118
        return SIZE;
118
        return SIZE;
119
    }
119
    }
120
    public String toFormulaString(SheetReferences refs)
120
    public String toFormulaString(Workbook book)
121
    {
121
    {
122
        return "ERR#";
122
        return "ERR#";
123
    }
123
    }
(-)src/java/org/apache/poi/hssf/record/formula/MemFuncPtg.java (-2 / +2 lines)
Lines 59-66 Link Here
59
 */
59
 */
60
package org.apache.poi.hssf.record.formula;
60
package org.apache.poi.hssf.record.formula;
61
import org.apache.poi.hssf.model.Workbook;
61
import org.apache.poi.util.LittleEndian;
62
import org.apache.poi.util.LittleEndian;
62
import org.apache.poi.hssf.util.SheetReferences;
63
/**
63
/**
64
 * @author Glen Stampoultzis (glens at apache.org)
64
 * @author Glen Stampoultzis (glens at apache.org)
Lines 96-102 Link Here
96
        LittleEndian.putShort( array, offset + 1, (short)field_1_len_ref_subexpression );
96
        LittleEndian.putShort( array, offset + 1, (short)field_1_len_ref_subexpression );
97
    }
97
    }
98
    public String toFormulaString( SheetReferences refs )
98
    public String toFormulaString( Workbook book )
99
    {
99
    {
100
        return "";
100
        return "";
101
    }
101
    }
(-)src/java/org/apache/poi/hssf/record/formula/MissingArgPtg.java (-4 / +2 lines)
Lines 54-60 Link Here
54
package org.apache.poi.hssf.record.formula;
54
package org.apache.poi.hssf.record.formula;
55
import org.apache.poi.hssf.util.SheetReferences;
55
import org.apache.poi.hssf.model.Workbook;
56
/**
56
/**
57
 * Missing Function Arguments
57
 * Missing Function Arguments
Lines 91-97 Link Here
91
    }
91
    }
92
    public String toFormulaString(SheetReferences refs)
92
    public String toFormulaString(Workbook book)
93
    {
93
    {
94
        return " ";
94
        return " ";
95
    }
95
    }
Lines 103-107 Link Here
103
    }
103
    }
104
}
104
}
105
106
(-)src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java (-6 / +6 lines)
Lines 61-70 Link Here
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import java.util.List;
62
import java.util.List;
63
import org.apache.poi.hssf.util.SheetReferences;
63
import org.apache.poi.hssf.model.Workbook;
64
/**
64
/**
65
 * Implements the standard mathmatical multiplication - *
65
 * Implements the standard mathmatical multiplication operator "*".
66
 * @author  Andrew C. Oliver (acoliver at apache dot org)
66
 * @author  Andrew C. Oliver (acoliver at apache dot org)
67
 * @author Jason Height (jheight at chariot dot net dot au)
67
 * @author Jason Height (jheight at chariot dot net dot au)
68
 */
68
 */
Lines 114-120 Link Here
114
    }
114
    }
115
    public String toFormulaString(SheetReferences refs)
115
    public String toFormulaString(Workbook book)
116
    {
116
    {
117
        return "*";
117
        return "*";
118
    }
118
    }
Lines 123-131 Link Here
123
    {
123
    {
124
        StringBuffer buffer = new StringBuffer();
124
        StringBuffer buffer = new StringBuffer();
125
        buffer.append(operands[ 0 ].toFormulaString((SheetReferences)null));
125
        buffer.append(operands[ 0 ].toFormulaString((Workbook)null));
126
        buffer.append("*");
126
        buffer.append("*");
127
        buffer.append(operands[ 1 ].toFormulaString((SheetReferences)null));
127
        buffer.append(operands[ 1 ].toFormulaString((Workbook)null));
128
        return buffer.toString();
128
        return buffer.toString();
129
    }
129
    }
Lines 133-139 Link Here
133
        StringBuffer buffer = new StringBuffer();
133
        StringBuffer buffer = new StringBuffer();
134
        buffer.append(operands[ 0 ]);
134
        buffer.append(operands[ 0 ]);
135
        buffer.append(toFormulaString((SheetReferences)null));
135
        buffer.append(toFormulaString((Workbook)null));
136
        buffer.append(operands[ 1 ]);
136
        buffer.append(operands[ 1 ]);
137
        return buffer.toString();
137
        return buffer.toString();
138
    }
138
    }
(-)src/java/org/apache/poi/hssf/record/formula/NamePtg.java (-17 / +32 lines)
Lines 60-67 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import org.apache.poi.hssf.model.Workbook;
63
import org.apache.poi.hssf.record.NameRecord;
62
import org.apache.poi.util.LittleEndian;
64
import org.apache.poi.util.LittleEndian;
63
import org.apache.poi.hssf.util.SheetReferences;
64
/**
65
/**
65
 *
66
 *
Lines 73-82 Link Here
73
    extends Ptg
74
    extends Ptg
74
{
75
{
75
    public final static short sid  = 0x23;
76
    public final static short sid  = 0x23;
76
    private final static int  SIZE = 7;
77
    private final static int  SIZE = 5; // BIFF-8 only
77
    private short             field_1_ixti;   // unknown function
78
    private short             field_1_name_index;
78
    private short             field_2_label_index;
79
    private short             field_2_unused;
79
    private short             field_3_zero;   // reserved must be 0
80
    private NamePtg() {
80
    private NamePtg() {
Lines 85-93 Link Here
85
    /** Creates new NamePtg */
85
    /** Creates new NamePtg */
86
    public NamePtg(String name)
86
    public NamePtg(String name, Workbook book)
87
    {
87
    {
88
        //TODO
88
        final short n = (short) (book.getNumNames() + 1);
89
        NameRecord rec;
90
        for (short i = 1; i < n; i++) {
91
            rec = book.getNameRecord(i - 1);
92
            if (name.equals(rec.getNameText())) {
93
                field_1_name_index = i;
94
                return;
95
            }
96
        }
97
        rec = new NameRecord();
98
        rec.setNameText(name);
99
        rec.setNameTextLength((byte) name.length());
100
        book.addName(rec);
101
        field_1_name_index = n;
89
    }
102
    }
90
    /** Creates new NamePtg */
103
    /** Creates new NamePtg */
Lines 95-126 Link Here
95
    public NamePtg(byte [] data, int offset)
108
    public NamePtg(byte [] data, int offset)
96
    {
109
    {
97
        offset++;
110
        offset++;
98
        field_1_ixti        = LittleEndian.getShort(data, offset);
111
        field_1_name_index = LittleEndian.getShort(data, offset);
99
        field_2_label_index = LittleEndian.getShort(data, offset + 2);
112
        field_2_unused =     LittleEndian.getShort(data, offset + 2);
100
        field_3_zero        = LittleEndian.getShort(data, offset + 4);
101
    }
113
    }
102
    public void writeBytes(byte [] array, int offset)
114
    public void writeBytes(byte [] array, int offset)
103
    {
115
    {
116
        array[offset] = (byte) (NamePtg.sid + ptgClass);
117
        LittleEndian.putShort(array, offset + 1, field_1_name_index);
118
        LittleEndian.putShort(array, offset + 3, field_2_unused);
104
    }
119
    }
105
    public int getSize()
120
    public int getSize()
106
    {
121
    {
107
        return SIZE;
122
        return NamePtg.SIZE;
108
    }
123
    }
109
    public String toFormulaString(SheetReferences refs)
124
    public String toFormulaString(Workbook book)
110
    {
125
    {
111
        return "NO IDEA - NAME";
126
        NameRecord rec = book.getNameRecord(field_1_name_index - 1);
127
        return rec.getNameText();
112
    }
128
    }
113
    public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
129
    public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
114
    public Object clone() {
130
    public Object clone() {
115
      NamePtg ptg = new NamePtg();
131
      NamePtg ptg = new NamePtg();
116
      ptg.field_1_ixti = field_1_ixti;
132
      ptg.field_1_name_index = field_1_name_index;
117
      ptg.field_2_label_index = field_2_label_index;
133
      ptg.field_2_unused = field_2_unused;
118
      ptg.field_3_zero = field_3_zero;
119
      return ptg;
134
      return ptg;
120
    }
135
    }
121
}
136
}
(-)src/java/org/apache/poi/hssf/record/formula/NameXPtg.java (-2 / +2 lines)
Lines 60-67 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import org.apache.poi.hssf.model.Workbook;
62
import org.apache.poi.util.LittleEndian;
63
import org.apache.poi.util.LittleEndian;
63
import org.apache.poi.hssf.util.SheetReferences;
64
/**
64
/**
65
 *
65
 *
Lines 113-119 Link Here
113
        return SIZE;
113
        return SIZE;
114
    }
114
    }
115
    public String toFormulaString(SheetReferences refs)
115
    public String toFormulaString(Workbook book)
116
    {
116
    {
117
        return "NO IDEA - NAME";
117
        return "NO IDEA - NAME";
118
    }
118
    }
(-)src/java/org/apache/poi/hssf/record/formula/NotEqualPtg.java (-4 / +4 lines)
Lines 54-62 Link Here
54
package org.apache.poi.hssf.record.formula;
54
package org.apache.poi.hssf.record.formula;
55
import java.util.List;
55
import java.util.List;
56
import org.apache.poi.hssf.util.SheetReferences;
56
import org.apache.poi.hssf.model.Workbook;
57
/**
57
/**
58
 * Ptg class to implement not equal
58
 * Ptg class to implement not equal
Lines 101-107 Link Here
101
		  return 2;
101
		  return 2;
102
	 }
102
	 }
103
	 public String toFormulaString(SheetReferences refs)
103
	 public String toFormulaString(Workbook book)
104
	 {
104
	 {
105
		  return "<>";
105
		  return "<>";
106
	 }
106
	 }
Lines 111-117 Link Here
111
		  buffer.append(operands[ 0 ]);
111
		  buffer.append(operands[ 0 ]);
112
		  buffer.append(toFormulaString((SheetReferences)null));
112
		  buffer.append(toFormulaString((Workbook)null));
113
		  buffer.append(operands[ 1 ]);
113
		  buffer.append(operands[ 1 ]);
114
		  return buffer.toString();
114
		  return buffer.toString();
115
	 }
115
	 }
(-)src/java/org/apache/poi/hssf/record/formula/NumberPtg.java (-3 / +2 lines)
Lines 54-61 Link Here
54
package org.apache.poi.hssf.record.formula;
54
package org.apache.poi.hssf.record.formula;
55
import org.apache.poi.hssf.model.Workbook;
55
import org.apache.poi.util.LittleEndian;
56
import org.apache.poi.util.LittleEndian;
56
import org.apache.poi.hssf.util.SheetReferences;
57
/**
57
/**
58
 * Number
58
 * Number
59
 * Stores a floating point value in a formula
59
 * Stores a floating point value in a formula
Lines 113-119 Link Here
113
        return SIZE;
113
        return SIZE;
114
    }
114
    }
115
    public String toFormulaString(SheetReferences refs)
115
    public String toFormulaString(Workbook book)
116
    {
116
    {
117
        return "" + getValue();
117
        return "" + getValue();
118
    }
118
    }
Lines 125-128 Link Here
125
      return ptg;
125
      return ptg;
126
    }
126
    }
127
}
127
}
128
(-)src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java (-6 / +6 lines)
Lines 55-71 Link Here
55
package org.apache.poi.hssf.record.formula;
55
package org.apache.poi.hssf.record.formula;
56
import java.util.List;
56
import java.util.List;
57
import org.apache.poi.hssf.util.SheetReferences;
57
import org.apache.poi.hssf.model.Workbook;
58
58
/**
59
/**
59
 * While formula tokens are stored in RPN order and thus do not need parenthesis for
60
 * While formula tokens are stored in RPN order and thus do not need parenthesis for
60
 * precedence reasons, Parenthesis tokens ARE written to ensure that user entered
61
 * precedence reasons, Parenthesis tokens ARE written to ensure that user entered
61
 * parenthesis are displayed as-is on reading back
62
 * parenthesis are displayed as-is on reading back.
62
 *
63
 *
63
 * Avik Sengupta <lists@aviksengupta.com>
64
 * @author Avik Sengupta <lists@aviksengupta.com>
64
 * Andrew C. Oliver (acoliver at apache dot org)
65
 * @author Andrew C. Oliver (acoliver at apache dot org)
65
 * @author Jason Height (jheight at chariot dot net dot au)
66
 * @author Jason Height (jheight at chariot dot net dot au)
66
 */
67
 */
67
public class ParenthesisPtg
68
public class ParenthesisPtg
Lines 107-113 Link Here
107
        return 1;
107
        return 1;
108
    }
108
    }
109
    public String toFormulaString(SheetReferences refs)
109
    public String toFormulaString(Workbook book)
110
    {
110
    {
111
        return "()";
111
        return "()";
112
    }
112
    }
Lines 124-127 Link Here
124
    }
124
    }
125
}
125
}
126
(-)src/java/org/apache/poi/hssf/record/formula/PowerPtg.java (-3 / +4 lines)
Lines 60-68 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import java.util.List;
62
import java.util.List;
63
import org.apache.poi.hssf.util.SheetReferences;
63
import org.apache.poi.hssf.model.Workbook;
64
64
/**
65
/**
65
 *
66
 *
Lines 108-114 Link Here
108
        return 2;
108
        return 2;
109
    }
109
    }
110
    public String toFormulaString(SheetReferences refs)
110
    public String toFormulaString(Workbook book)
111
    {
111
    {
112
        return "^";
112
        return "^";
113
    }
113
    }
Lines 118-124 Link Here
118
        buffer.append(operands[ 0 ]);
118
        buffer.append(operands[ 0 ]);
119
        buffer.append(toFormulaString((SheetReferences)null));
119
        buffer.append(toFormulaString((Workbook)null));
120
        buffer.append(operands[ 1 ]);
120
        buffer.append(operands[ 1 ]);
121
        return buffer.toString();
121
        return buffer.toString();
122
    }
122
    }
(-)src/java/org/apache/poi/hssf/record/formula/Ptg.java (-5 / +4 lines)
Lines 60-72 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import java.util.ArrayList;
62
import org.apache.poi.hssf.model.Workbook;
63
import org.apache.poi.hssf.util.SheetReferences;
64
/**
63
/**
65
 *
64
 * Parse ThinG.
66
 * @author  andy
65
 * @author  andy
67
 * @author avik
66
 * @author avik
68
 * @author Jason Height (jheight at chariot dot net dot au)
67
 * @author Jason Height (jheight at chariot dot net dot au)
Lines 76-82 Link Here
76
{
75
{
77
    /** convert infix order ptg list to rpn order ptg list
76
    /* convert infix order ptg list to rpn order ptg list
78
     * @return List ptgs in RPN order
77
     * @return List ptgs in RPN order
79
     * @param infixPtgs List of ptgs in infix order
78
     * @param infixPtgs List of ptgs in infix order
80
     */
79
     */
Lines 341-347 Link Here
341
    /**
340
    /**
342
     * return a string representation of this token alone
341
     * return a string representation of this token alone
343
     */
342
     */
344
    public abstract String toFormulaString(SheetReferences refs);
343
    public abstract String toFormulaString(Workbook book);
345
    /**
344
    /**
346
     * dump a debug representation (hexdump) to a string
345
     * dump a debug representation (hexdump) to a string
347
     */
346
     */
(-)src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java (-4 / +5 lines)
Lines 56-73 Link Here
56
package org.apache.poi.hssf.record.formula;
56
package org.apache.poi.hssf.record.formula;
57
import org.apache.poi.util.LittleEndian;
57
import org.apache.poi.hssf.model.Workbook;
58
import org.apache.poi.hssf.util.RangeAddress;
59
import org.apache.poi.hssf.util.CellReference;
58
import org.apache.poi.hssf.util.CellReference;
59
import org.apache.poi.hssf.util.RangeAddress;
60
import org.apache.poi.hssf.util.SheetReferences;
60
import org.apache.poi.hssf.util.SheetReferences;
61
import org.apache.poi.util.BitField;
61
import org.apache.poi.util.BitField;
62
import org.apache.poi.hssf.model.Workbook;
62
import org.apache.poi.util.LittleEndian;
63
/**
63
/**
64
 * Title:        Reference 3D Ptg <P>
64
 * Title:        Reference 3D Ptg <P>
65
 * Description:  Defined a cell in extern sheet. <P>
65
 * Description:  Defined a cell in extern sheet. <P>
66
 * REFERENCE:  <P>
66
 * REFERENCE:  <P>
67
 * @author Libin Roman (Vista Portal LDT. Developer)
67
 * @author Libin Roman (Vista Portal LDT. Developer)
68
 * @author Jason Height (jheight at chariot dot net dot au)
68
 * @author Jason Height (jheight at chariot dot net dot au)
69
 * @version 1.0-pre
69
 * @version 1.0-pre
Lines 193-199 Link Here
193
    }
193
    }
194
    public String toFormulaString(SheetReferences refs) {
194
    public String toFormulaString(Workbook book) {
195
        SheetReferences refs = book.getSheetReferences();
195
        StringBuffer retval = new StringBuffer();
196
        StringBuffer retval = new StringBuffer();
196
        if (refs != null) {
197
        if (refs != null) {
197
            retval.append(refs.getSheetName((int)this.field_1_index_extern_sheet));
198
            retval.append(refs.getSheetName((int)this.field_1_index_extern_sheet));
(-)src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java (-4 / +4 lines)
Lines 60-70 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import org.apache.poi.util.LittleEndian;
62
import org.apache.poi.hssf.model.Workbook;
63
import org.apache.poi.util.BitField;
64
import org.apache.poi.hssf.util.CellReference;
63
import org.apache.poi.hssf.util.CellReference;
65
import org.apache.poi.hssf.util.SheetReferences;
64
import org.apache.poi.util.BitField;
65
import org.apache.poi.util.LittleEndian;
66
/**
66
/**
67
 * ReferencePtg - handles references (such as A1, A2, IA4)
67
 * ReferencePtg - handles references (such as A1, A2, IA4)
Lines 179-185 Link Here
179
        return SIZE;
179
        return SIZE;
180
    }
180
    }
181
    public String toFormulaString(SheetReferences refs)
181
    public String toFormulaString(Workbook book)
182
    {
182
    {
183
        //TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
183
        //TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
184
        return (new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).toString();
184
        return (new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).toString();
(-)src/java/org/apache/poi/hssf/record/formula/StringPtg.java (-6 / +7 lines)
Lines 54-66 Link Here
54
package org.apache.poi.hssf.record.formula;
54
package org.apache.poi.hssf.record.formula;
55
import org.apache.poi.util.LittleEndian;
55
import org.apache.poi.hssf.model.Workbook;
56
import org.apache.poi.hssf.util.SheetReferences;
56
import org.apache.poi.util.LittleEndian;
57
/**
57
/**
58
 * Number
58
 * Stores a String value in a formula value.
59
 * Stores a String value in a formula value stored in the format <length 2 bytes>char[]
59
 *
60
 * Stored in the format <tt>&lt;length 2 bytes&gt;char[]</tt>.
61
 *
60
 * @author  Werner Froidevaux
62
 * @author  Werner Froidevaux
61
 * @author Jason Height (jheight at chariot dot net dot au)
63
 * @author Jason Height (jheight at chariot dot net dot au)
62
 */
64
 */
Lines 116-122 Link Here
116
        return field_1_value.length() + 3;
118
        return field_1_value.length() + 3;
117
    }
119
    }
118
    public String toFormulaString(SheetReferences refs)
120
    public String toFormulaString(Workbook book)
119
    {
121
    {
120
        return "\""+getValue()+"\"";
122
        return "\""+getValue()+"\"";
121
    }
123
    }
Lines 131-134 Link Here
131
   }
133
   }
132
}
134
}
133
(-)src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java (-2 / +2 lines)
Lines 61-67 Link Here
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import java.util.List;
62
import java.util.List;
63
import org.apache.poi.hssf.util.SheetReferences;
63
import org.apache.poi.hssf.model.Workbook;
64
/**
64
/**
65
 *
65
 *
Lines 105-111 Link Here
105
        return 2;
105
        return 2;
106
    }
106
    }
107
    public String toFormulaString(SheetReferences refs)
107
    public String toFormulaString(Workbook book)
108
    {
108
    {
109
        return "-";
109
        return "-";
110
    }
110
    }
(-)src/java/org/apache/poi/hssf/record/formula/UnionPtg.java (-2 / +2 lines)
Lines 54-60 Link Here
54
package org.apache.poi.hssf.record.formula;
54
package org.apache.poi.hssf.record.formula;
55
import org.apache.poi.hssf.util.SheetReferences;
55
import org.apache.poi.hssf.model.Workbook;
56
/**
56
/**
57
 * @author Glen Stampoultzis (glens at apache.org)
57
 * @author Glen Stampoultzis (glens at apache.org)
Lines 95-101 Link Here
95
    }
95
    }
96
    /** Implementation of method from Ptg */
96
    /** Implementation of method from Ptg */
97
    public String toFormulaString(SheetReferences refs)
97
    public String toFormulaString(Workbook book)
98
    {
98
    {
99
        return ",";
99
        return ",";
100
    }
100
    }
(-)src/java/org/apache/poi/hssf/record/formula/UnknownPtg.java (-2 / +5 lines)
Lines 60-66 Link Here
60
 */
60
 */
61
package org.apache.poi.hssf.record.formula;
61
package org.apache.poi.hssf.record.formula;
62
import org.apache.poi.hssf.util.SheetReferences;
62
import org.apache.poi.hssf.model.Workbook;
63
64
65
63
/**
66
/**
64
 *
67
 *
Lines 94-100 Link Here
94
        return size;
97
        return size;
95
    }
98
    }
96
    public String toFormulaString(SheetReferences refs)
99
    public String toFormulaString(Workbook book)
97
    {
100
    {
98
        return "UNKNOWN";
101
        return "UNKNOWN";
99
    }
102
    }
(-)src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (-3 / +1 lines)
Lines 73-79 Link Here
73
import org.apache.poi.hssf.record.ExtendedFormatRecord;
73
import org.apache.poi.hssf.record.ExtendedFormatRecord;
74
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
74
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
75
import org.apache.poi.hssf.record.formula.Ptg;
75
import org.apache.poi.hssf.record.formula.Ptg;
76
import org.apache.poi.hssf.util.SheetReferences;
77
//import org.apache.poi.hssf.record.formula.FormulaParser;
76
//import org.apache.poi.hssf.record.formula.FormulaParser;
Lines 748-755 Link Here
748
    public String getCellFormula() {
747
    public String getCellFormula() {
749
        //Workbook.currentBook=book;
748
        //Workbook.currentBook=book;
750
        SheetReferences refs = book.getSheetReferences();
749
        String retval = FormulaParser.toFormulaString(book,
751
        String retval = FormulaParser.toFormulaString(refs,
752
                ((FormulaRecordAggregate)sheet.getValueRecord(row,cellNum)).getFormulaRecord().getParsedExpression());
750
                ((FormulaRecordAggregate)sheet.getValueRecord(row,cellNum)).getFormulaRecord().getParsedExpression());
753
        //Workbook.currentBook=null;
751
        //Workbook.currentBook=null;
754
        return retval;
752
        return retval;
(-)src/java/org/apache/poi/hssf/usermodel/HSSFName.java (-5 / +3 lines)
Lines 74-78 Link Here
74
     *
74
     *
75
     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createName()
75
     * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createName()
76
     * @param name the Name Record
76
     * @param name the Name Record
77
     * @param book - lowlevel Workbook object associated with the sheet.
77
     * @param book lowlevel Workbook object associated with the sheet
78
     * @param book the Workbook */
78
     */
79
    protected HSSFName(Workbook book, NameRecord name) {
79
    protected HSSFName(Workbook book, NameRecord name) {
80
        this.book = book;
80
        this.book = book;
Lines 123-130 Link Here
123
    public String getReference() {
123
    public String getReference() {
124
        String result;
124
        String result;
125
        SheetReferences refs = book.getSheetReferences();
125
        result = name.getAreaReference(book);
126
        result = name.getAreaReference(refs);
127
        return result;
126
        return result;
128
    }
127
    }
Lines 167-170 Link Here
167
    }
166
    }
168
}
167
}
169
(-)src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (-5 / +5 lines)
Lines 267-274 Link Here
267
    /**
267
    /**
268
     * set the sheet name.
268
     * set the sheet name.
269
     * @param sheet number (0 based)
269
     * @param sheet sheet number (0 based)
270
     * @param sheet name
270
     * @param name sheet name
271
     */
271
     */
272
    public void setSheetName(int sheet, String name)
272
    public void setSheetName(int sheet, String name)
Lines 827-833 Link Here
827
    }
827
    }
828
	/**
828
	/**
829
	 * Sets the printarea for the sheet provided
829
	 * Sets the printarea for the sheet provided.
830
	 * <p>
830
	 * <p>
831
	 * i.e. Reference = $A$1:$B$2
831
	 * i.e. Reference = $A$1:$B$2
832
	 * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
832
	 * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
Lines 851-857 Link Here
851
	/**
851
	/**
852
	 * For the Convenience of Java Programmers maintaining pointers.
852
	 * For the Convenience of Java Programmers maintaining pointers.
853
	 * @see setPrintArea(int, String)
853
	 * @see #setPrintArea(int, String)
854
	 * @param sheetIndex Zero-based sheet index (0 = First Sheet)
854
	 * @param sheetIndex Zero-based sheet index (0 = First Sheet)
855
	 * @param startColumn Column to begin printarea
855
	 * @param startColumn Column to begin printarea
856
	 * @param endColumn Column to end the printarea
856
	 * @param endColumn Column to end the printarea
Lines 883-889 Link Here
883
		if (name == null) return null;
883
		if (name == null) return null;
884
		//adding one here because 0 indicates a global named region; doesnt make sense for print areas
884
		//adding one here because 0 indicates a global named region; doesnt make sense for print areas
885
		return name.getAreaReference(workbook.getSheetReferences());
885
		return name.getAreaReference(workbook);
886
	}
886
	}
887
    /**
887
    /**
(-)src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (-3 / +15 lines)
Lines 53-62 Link Here
53
 */
53
 */
54
package org.apache.poi.hssf.model;
54
package org.apache.poi.hssf.model;
55
import junit.framework.TestCase;
55
import junit.framework.TestCase;
56
import org.apache.poi.hssf.record.formula.*;
56
import org.apache.poi.hssf.record.formula.*;
57
import org.apache.poi.hssf.util.SheetReferences;
58
/**
57
/**
59
 * Test the low level formula parser functionality. High level tests are to
58
 * Test the low level formula parser functionality. High level tests are to
Lines 145-151 Link Here
145
        assertEquals(true, flag.getValue());
144
        assertEquals(true, flag.getValue());
146
        assertEquals("Y", y.getValue());
145
        assertEquals("Y", y.getValue());
147
        assertEquals("N", n.getValue());
146
        assertEquals("N", n.getValue());
148
        assertEquals("IF", funif.toFormulaString(new SheetReferences()));
147
        assertEquals("IF", funif.toFormulaString((Workbook) null));
149
        assertTrue("Goto ptg exists", goto1.isGoto());
148
        assertTrue("Goto ptg exists", goto1.isGoto());
150
    }
149
    }
Lines 285-290 Link Here
285
	}
284
	}
285
    public void testMacroFunction() {
286
        Workbook w = new Workbook();
287
        FormulaParser fp = new FormulaParser("FOO()", w);
288
        fp.parse();
289
        Ptg[] ptg = fp.getRPNPtg();
290
291
        AbstractFunctionPtg tfunc = (AbstractFunctionPtg) ptg[0];
292
        assertEquals("externalflag", tfunc.getName());
293
294
        NamePtg tname = (NamePtg) ptg[1];
295
        assertEquals("FOO", tname.toFormulaString(w));
296
    }
297
286
     public static void main(String [] args) {
298
     public static void main(String [] args) {
287
        System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser");
299
        System.out.println("Testing org.apache.poi.hssf.record.formula.FormulaParser");
288
        junit.textui.TestRunner.run(TestFormulaParser.class);
300
        junit.textui.TestRunner.run(TestFormulaParser.class);
(-)src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java (-6 / +52 lines)
Lines 744-750 Link Here
744
    }
744
    }
745
    public void testSheetFunctions()
745
    public void testSheetFunctions()
746
        throws java.io.IOException
746
        throws IOException
747
    {
747
    {
748
        String filename = System.getProperty("HSSF.testdata.path");
748
        String filename = System.getProperty("HSSF.testdata.path");
Lines 818-824 Link Here
818
    }
818
    }
819
    public void testStringFormulas()
819
    public void testStringFormulas()
820
        throws java.io.IOException
820
        throws IOException
821
    {
821
    {
822
        String readFilename = System.getProperty("HSSF.testdata.path");
822
        String readFilename = System.getProperty("HSSF.testdata.path");
Lines 852-858 Link Here
852
    public void testLogicalFormulas()
852
    public void testLogicalFormulas()
853
        throws java.io.IOException
853
        throws IOException
854
    {
854
    {
855
            File file = File.createTempFile("testLogicalFormula",".xls");
855
            File file = File.createTempFile("testLogicalFormula",".xls");
Lines 880-886 Link Here
880
    }
880
    }
881
    public void testDateFormulas()
881
    public void testDateFormulas()
882
        throws java.io.IOException
882
        throws IOException
883
    {
883
    {
884
        String readFilename = System.getProperty("HSSF.testdata.path");
884
        String readFilename = System.getProperty("HSSF.testdata.path");
Lines 918-924 Link Here
918
    public void testIfFormulas()
918
    public void testIfFormulas()
919
        throws java.io.IOException
919
        throws IOException
920
    {
920
    {
921
        String readFilename = System.getProperty("HSSF.testdata.path");
921
        String readFilename = System.getProperty("HSSF.testdata.path");
Lines 1008-1014 Link Here
1008
    }
1008
    }
1009
	public void testSumIf()
1009
	public void testSumIf()
1010
		throws java.io.IOException
1010
		throws IOException
1011
	{
1011
	{
1012
		String readFilename = System.getProperty("HSSF.testdata.path");
1012
		String readFilename = System.getProperty("HSSF.testdata.path");
1013
		String function ="SUMIF(A1:A5,\">4000\",B1:B5)";
1013
		String function ="SUMIF(A1:A5,\">4000\",B1:B5)";
Lines 1060-1065 Link Here
1060
		assertTrue("sumif == 0 bytes", file.length() > 0);
1060
		assertTrue("sumif == 0 bytes", file.length() > 0);
1061
	}
1061
	}
1062
    public void testSquareMacro() throws IOException {
1063
        File dir = new File(System.getProperty("HSSF.testdata.path"));
1064
        File xls = new File(dir, "SquareMacro.xls");
1065
        FileInputStream in = new FileInputStream(xls);
1066
        HSSFWorkbook w;
1067
        try {
1068
            w = new HSSFWorkbook(in);
1069
        } finally {
1070
            in.close();
1071
        }
1072
        HSSFSheet s0 = w.getSheetAt(0);
1073
        HSSFRow[] r = {s0.getRow(0), s0.getRow(1)};
1074
1075
        HSSFCell a1 = r[0].getCell((short) 0);
1076
        assertEquals("square(1)", a1.getCellFormula());
1077
        assertEquals(1d, a1.getNumericCellValue(), 1e-9);
1078
1079
        HSSFCell a2 = r[1].getCell((short) 0);
1080
        assertEquals("square(2)", a2.getCellFormula());
1081
        assertEquals(4d, a2.getNumericCellValue(), 1e-9);
1082
1083
        HSSFCell b1 = r[0].getCell((short) 1);
1084
        assertEquals("IF(TRUE,square(1))", b1.getCellFormula());
1085
        assertEquals(4d, b1.getNumericCellValue(), 1e-9);
1086
1087
        HSSFCell b2 = r[1].getCell((short) 1);
1088
        assertEquals("IF(TRUE,square(2))", b2.getCellFormula());
1089
        assertEquals(4d, b2.getNumericCellValue(), 1e-9);
1090
1091
        HSSFCell c1 = r[0].getCell((short) 2);
1092
        assertEquals("square(square(1))", c1.getCellFormula());
1093
        assertEquals(1d, c1.getNumericCellValue(), 1e-9);
1094
1095
        HSSFCell c2 = r[1].getCell((short) 2);
1096
        assertEquals("square(square(2))", c2.getCellFormula());
1097
        assertEquals(16d, c2.getNumericCellValue(), 1e-9);
1098
1099
        HSSFCell d1 = r[0].getCell((short) 3);
1100
        assertEquals("square(one())", d1.getCellFormula());
1101
        assertEquals(1d, d1.getNumericCellValue(), 1e-9);
1102
1103
        HSSFCell d2 = r[1].getCell((short) 3);
1104
        assertEquals("square(two())", d2.getCellFormula());
1105
        assertEquals(4d, d2.getNumericCellValue(), 1e-9);
1106
    }
1107
1062
    public static void main(String [] args) {
1108
    public static void main(String [] args) {
1063
        System.out
1109
        System.out
1064
        .println("Testing org.apache.poi.hssf.usermodel.TestFormulas");
1110
        .println("Testing org.apache.poi.hssf.usermodel.TestFormulas");

Return to bug 21444