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

(-)src/java/org/apache/poi/hssf/dev/FormulaViewer.java (-3 / +3 lines)
Line 144 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)");
Line 233 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 (-41 / +48 lines)
Lines 64-65 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 795-807 Link Here
795
    /**
794
    /**
796
     * Convience method which takes in a list then passes it to the other toFormulaString
795
     * Convience method which takes in a list then passes it to the other toFormulaString
797
     * signature.
796
     * signature.
798
     * @param lptgs - list of ptgs, can be null
797
     * @param book   workbook for 3D and named references
798
     * @param lptgs  list of Ptg, can be null or empty
799
     * @return a human readable String
799
     */
800
     */
800
    public static String toFormulaString(SheetReferences refs, List lptgs) {
801
    public static String toFormulaString(Workbook book, List lptgs) {
801
        String retval = null;
802
        String retval = null;
802
        if (lptgs == null || lptgs.size() == 0) return "#NAME";
803
        if (lptgs == null || lptgs.size() == 0) return "#NAME";
803
        Ptg[] ptgs = new Ptg[lptgs.size()];
804
        Ptg[] ptgs = new Ptg[lptgs.size()];
804
        ptgs = (Ptg[])lptgs.toArray(ptgs);
805
        ptgs = (Ptg[])lptgs.toArray(ptgs);
805
        retval = toFormulaString(refs, ptgs);
806
        retval = toFormulaString(book, ptgs);
806
        return retval;
807
        return retval;
807
    }
808
    }
808
    /** Static method to convert an array of Ptgs in RPN order
809
    /**
809
     *  to a human readable string format in infix mode
810
     * Static method to convert an array of Ptgs in RPN order
810
     *  @param ptgs - array of ptgs, can be null or empty
811
     * to a human readable string format in infix mode.
812
     * @param book  workbook for named and 3D references
813
     * @param ptgs  array of Ptg, can be null or empty
814
     * @return a human readable String
811
     */
815
     */
812
    public static String toFormulaString(SheetReferences refs, Ptg[] ptgs) {
816
    public static String toFormulaString(Workbook book, Ptg[] ptgs) {
813
        if (ptgs == null || ptgs.length == 0) return "#NAME";
817
        if (ptgs == null || ptgs.length == 0) return "#NAME";
814
        java.util.Stack stack = new java.util.Stack();
818
        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;
819
        AttrPtg ifptg = null;
821
        for (int i=0;i<numPtgs;i++) {
820
822
           // Excel allows to have AttrPtg at position 0 (such as Blanks) which
821
           // Excel allows to have AttrPtg at position 0 (such as Blanks) which
823
           // do not have any operands. Skip them.
822
           // do not have any operands. Skip them.
824
            if (ptgs[i] instanceof OperationPtg && i>0) {
823
        stack.push(ptgs[0].toFormulaString(book));
825
                  o = (OperationPtg) ptgs[i];
826
                  if (o instanceof AttrPtg && ((AttrPtg)o).isOptimizedIf()) {
824
        for (int i = 1; i < ptgs.length; i++) {
827
                        ifptg=(AttrPtg)o;
825
            if (! (ptgs[i] instanceof OperationPtg)) {
828
                  } else {
826
                stack.push(ptgs[i].toFormulaString(book));
827
                continue;
828
            }
829
                      numOperands = o.getNumberOfOperands();
829
            if (ptgs[i] instanceof AttrPtg && ((AttrPtg) ptgs[i]).isOptimizedIf()) {
830
                      operands = new String[numOperands];
830
                ifptg = (AttrPtg) ptgs[i];
831
                continue;
832
            }
831
                      for (int j=0;j<numOperands;j++) {
833
            final OperationPtg o = (OperationPtg) ptgs[i];
832
                          operands[numOperands-j-1] = (String) stack.pop(); //TODO: catch stack underflow and throw parse exception.
834
            final String[] operands = new String[o.getNumberOfOperands()];
835
836
            for (int j = operands.length; j > 0; j--) {
837
                //TODO: catch stack underflow and throw parse exception.
838
                operands[j - 1] = (String) stack.pop();
833
                      }
839
                      }
834
                      if ( (o instanceof AbstractFunctionPtg) &&
840
            stack.push(o.toFormulaString(operands));
835
                            ((AbstractFunctionPtg)o).getName().equals("specialflag") &&
841
            if (!(o instanceof AbstractFunctionPtg)) continue;
836
                            ifptg != null
842
837
                            ) {
843
            final AbstractFunctionPtg f = (AbstractFunctionPtg) o;
844
            final String fname = f.getName();
845
            if (fname == null) continue;
846
847
            if ((ifptg != null) && (fname.equals("specialflag"))) {
838
                             // this special case will be way different.
848
                             // this special case will be way different.
839
                             result = ifptg.toFormulaString(
849
                stack.push(ifptg.toFormulaString(new String[]{(String) stack.pop()}));
840
                                  new String[] {(o.toFormulaString(operands))}
841
                                                           );
842
                             ifptg = null;
850
                             ifptg = null;
843
                      } else {
851
                continue;
844
                        result = o.toFormulaString(operands);
845
                      }
846
                      stack.push(result);
847
                  }
852
                  }
848
853
            if (fname.equals("externalflag")) {
849
            } else {
854
                final String tos = (String) stack.pop();
850
                stack.push(ptgs[i].toFormulaString(refs));
855
                final String curry = tos.substring(13).replace(',','(');
856
                return curry;
851
            }
857
            }
852
        }
858
        }
853
        return (String) stack.pop(); //TODO: catch stack underflow and throw parse exception.
859
        // TODO: catch stack underflow and throw parse exception.
860
        return (String) stack.pop();
854
    }
861
    }
862
863
855
    /** Create a tree representation of the RPN token array
864
    /** Create a tree representation of the RPN token array
856
     *used to run the class(RVA) change algo
865
     *used to run the class(RVA) change algo
857
     */
866
     */
Lines 890-900 Link Here
890
     *   Useful for testing
899
     *   Useful for testing
891
     */
900
     */
892
    public String toString() {
901
    public String toString() {
893
        SheetReferences refs = null;
894
        if (book!=null)  book.getSheetReferences();
895
        StringBuffer buf = new StringBuffer();
902
        StringBuffer buf = new StringBuffer();
896
           for (int i=0;i<tokens.size();i++) {
903
           for (int i=0;i<tokens.size();i++) {
897
            buf.append( ( (Ptg)tokens.get(i)).toFormulaString(refs));
904
            buf.append( ( (Ptg)tokens.get(i)).toFormulaString(book));
898
            buf.append(' ');
905
            buf.append(' ');
899
        }
906
        }
900
        return buf.toString();
907
        return buf.toString();
(-)src/java/org/apache/poi/hssf/record/NameRecord.java (-13 / +67 lines)
Line 55 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)
69
 * Description:  Defines a named range within a workbook. <P>
69
 * @Description  Defines a named range within a workbook.
70
 * REFERENCE:  <P>
70
 * @REFERENCE
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-128 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-197 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
Line 252 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-347 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-410 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
	 */
Line 511 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-653 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;
Line 727 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 (-3 / +3 lines)
Lines 53-54 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 104-105 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 389-394 Link Here
389
        dmap.put(new Integer(252),"FREQUENCY");
388
        dmap.put(new Integer(252),"FREQUENCY");
390
        dmap.put(new Integer(253),"ADDTOOLBAR");
389
        dmap.put(new Integer(253),"ADDTOOLBAR");
391
        dmap.put(new Integer(254),"DELETETOOLBAR");
390
        dmap.put(new Integer(254),"DELETETOOLBAR");
391
        dmap.put(new Integer(255),"externalflag");
392
        dmap.put(new Integer(256),"RESETTOOLBAR");
392
        dmap.put(new Integer(256),"RESETTOOLBAR");
393
        dmap.put(new Integer(257),"EVALUATE");
393
        dmap.put(new Integer(257),"EVALUATE");
394
        dmap.put(new Integer(258),"GETTOOLBAR");
394
        dmap.put(new Integer(258),"GETTOOLBAR");
(-)src/java/org/apache/poi/hssf/record/formula/AddPtg.java (-3 / +3 lines)
Lines 60-61 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
 * Addition operator PTG the "+" binomial operator.  If you need more
65
 * Addition operator PTG the "+" binomial operator.  If you need more
Line 113 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 (-7 / +7 lines)
Line 64 Link Here
64
import org.apache.poi.util.BitField;
64
import org.apache.poi.util.BitField;
65
/**
65
/**
66
 * Title:        Area 3D Ptg - 3D referecnce (Sheet + Area)<P>
66
 * @Title        Area 3D Ptg - 3D referecnce (Sheet + Area)
67
 * Description:  Defined a area in Extern Sheet. <P>
67
 * @Description  Defined a area in Extern Sheet.
68
 * REFERENCE:  <P>
68
 * @REFERENCE
69
 * @author Libin Roman (Vista Portal LDT. Developer)
69
 * @author Libin Roman (Vista Portal LDT. Developer)
70
 * @author avik
70
 * @author avik
71
 * @author Jason Height (jheight at chariot dot net dot au)
71
 * @author Jason Height (jheight at chariot dot net dot au)
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
	{
Line 253 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
	{
Line 291 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 ) );
Line 351 Link Here
351
}
352
}
352
(-)src/java/org/apache/poi/hssf/record/formula/AreaPtg.java (-7 / +6 lines)
Lines 60-61 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.
Line 171 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
    {
Line 267 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-306 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-61 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-216 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-227 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-60 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-115 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)
Line 62 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-109 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)
Line 62 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-109 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
    }
Line 117 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)
Line 62 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-108 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
    }
Line 117 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-61 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-103 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-54 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-99 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
    }
Line 108 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)
Line 61 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 ">"
Line 131 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-61 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-117 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-54 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-100 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
	 }
Line 109 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)
Line 63 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
Line 140 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
    }
Line 180 Link Here
180
    }
180
    }
181
}
181
}
182
183
184
(-)src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java (-2 / +2 lines)
Lines 60-61 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-119 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-60 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-97 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)
Line 54 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
Line 91 Link Here
91
    }
91
    }
92
    public String toFormulaString(SheetReferences refs)
92
    public String toFormulaString(Workbook book)
93
    {
93
    {
94
        return " ";
94
        return " ";
95
    }
95
    }
Line 103 Link Here
103
    }
103
    }
104
}
104
}
105
106
(-)src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java (-6 / +6 lines)
Line 61 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
 */
Line 114 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-124 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
    }
Line 133 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 (-4 / +6 lines)
Lines 60-61 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
 *
Line 106 Link Here
106
    public int getSize()
107
    public int getSize()
107
    {
108
    {
108
        return SIZE;
109
        return (field_3_zero == 0) ? SIZE : SIZE - 2;
109
    }
110
    }
110
    public String toFormulaString(SheetReferences refs)
111
    public String toFormulaString(Workbook book)
111
    {
112
    {
112
        return "NO IDEA - NAME";
113
        NameRecord rec = book.getNameRecord(field_1_ixti - 1);
114
        return rec.getNameText();
113
    }
115
    }
114
    public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
116
    public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
(-)src/java/org/apache/poi/hssf/record/formula/NameXPtg.java (-2 / +2 lines)
Lines 60-61 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-114 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)
Line 54 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-102 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
	 }
Line 111 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)
Line 54 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-114 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 (-7 / +6 lines)
Line 55 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
 * While formula tokens are stored in RPN order and thus do not need parenthesis for
59
 * 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
60
 * precedence reasons, Parenthesis tokens ARE written to ensure that user entered
61
 * parenthesis are displayed as-is on reading back
61
 * parenthesis are displayed as-is on reading back.
62
 *
62
 *
63
 * Avik Sengupta <lists@aviksengupta.com>
63
 * @author Avik Sengupta <lists@aviksengupta.com>
64
 * Andrew C. Oliver (acoliver at apache dot org)
64
 * @author Andrew C. Oliver (acoliver at apache dot org)
65
 * @author Jason Height (jheight at chariot dot net dot au)
65
 * @author Jason Height (jheight at chariot dot net dot au)
66
 */
66
 */
67
public class ParenthesisPtg
67
public class ParenthesisPtg
Lines 107-108 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
    }
Line 124 Link Here
124
    }
124
    }
125
}
125
}
126
(-)src/java/org/apache/poi/hssf/record/formula/PowerPtg.java (-4 / +4 lines)
Lines 60-61 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
 *
Lines 108-109 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
    }
Line 118 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 (-6 / +18 lines)
Lines 60-61 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 java.util.ArrayList;
63
import org.apache.poi.hssf.model.Workbook;
64
import org.apache.poi.hssf.util.SheetReferences;
65
/**
64
/**
66
 *
65
 * Parse ThinG.
67
 * @author  andy
66
 * @author  andy
68
 * @author avik
67
 * @author avik
69
 * @author Jason Height (jheight at chariot dot net dot au)
68
 * @author Jason Height (jheight at chariot dot net dot au)
Line 76 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 140-144 Link Here
140
        final byte arrayFunc = FuncPtg.sid + 0x40;
139
        final byte arrayFunc = FuncPtg.sid + 0x40;
141
        final byte valueFuncVar = FuncVarPtg.sid +0x20;
140
        final byte valueFuncVar = FuncVarPtg.sid +0x20;
142
        final byte arrayFuncVar = FuncVarPtg.sid+0x40;
141
        final byte arrayFuncVar = FuncVarPtg.sid+0x40;
142
        final byte valueFuncCE = FuncCEPtg.sid + 0x20;
143
        final byte arrayFuncCE = FuncCEPtg.sid + 0x40;
143
        final byte valueArea = AreaPtg.sid + 0x20;
144
        final byte valueArea = AreaPtg.sid + 0x20;
144
        final byte arrayArea = AreaPtg.sid + 0x40;
145
        final byte arrayArea = AreaPtg.sid + 0x40;
Lines 264-265 Link Here
264
                retval = new FuncVarPtg(data, offset);
265
                retval = new FuncVarPtg(data, offset);
265
                break;
266
                break;
267
            case FuncCEPtg.sid :
268
                retval = new FuncCEPtg(data, offset);
269
                break;
270
271
            case valueFuncCE :
272
                retval = new FuncCEPtg(data, offset);
273
                break;
274
            case arrayFuncCE :
275
                retval = new FuncCEPtg(data, offset);
276
                break;
277
266
            case NumberPtg.sid :
278
            case NumberPtg.sid :
267
               retval = new NumberPtg(data, offset);
279
               retval = new NumberPtg(data, offset);
268
               break;
280
               break;
Lines 341-347 Link Here
341
    /**
353
    /**
342
     * return a string representation of this token alone
354
     * return a string representation of this token alone
343
     */
355
     */
344
    public abstract String toFormulaString(SheetReferences refs);
356
    public abstract String toFormulaString(Workbook book);
345
    /**
357
    /**
346
     * dump a debug representation (hexdump) to a string
358
     * dump a debug representation (hexdump) to a string
347
     */
359
     */
(-)src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java (-7 / +8 lines)
Line 56 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
65
 * Description:  Defined a cell in extern sheet. <P>
65
 * @Description  Defined a cell in extern sheet.
66
 * REFERENCE:  <P>
66
 * @REFERENCE
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
Line 193 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-61 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-180 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)
Line 54 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-117 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
    }
Line 131 Link Here
131
   }
133
   }
132
}
134
}
133
(-)src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java (-2 / +2 lines)
Line 61 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-106 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)
Line 54 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)
Line 95 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-61 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-95 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 (-4 / +1 lines)
Line 725 Link Here
725
    }
725
    }
726
    public String getCellFormula() {
726
    public String getCellFormula() {
727
        //Workbook.currentBook=book;
727
        String retval = FormulaParser.toFormulaString(book, ((FormulaRecordAggregate)record).getFormulaRecord().getParsedExpression());
728
        SheetReferences refs = book.getSheetReferences();
729
        String retval = FormulaParser.toFormulaString(refs, ((FormulaRecordAggregate)record).getFormulaRecord().getParsedExpression());
730
        //Workbook.currentBook=null;
731
        return retval;
728
        return retval;
732
    }
729
    }
(-)src/java/org/apache/poi/hssf/usermodel/HSSFName.java (-7 / +5 lines)
Line 60 Link Here
60
import org.apache.poi.hssf.util.SheetReferences;
60
import org.apache.poi.hssf.util.SheetReferences;
61
/**
61
/**
62
 * Title:        High Level Represantion of Named Range <P>
62
 * @Title        High Level Represantion of Named Range
63
 * REFERENCE:  <P>
63
 * @REFERENCE
64
 * @author Libin Roman (Vista Portal LDT. Developer)
64
 * @author Libin Roman (Vista Portal LDT. Developer)
65
 */
65
 */
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;
Line 123 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
    }
Line 167 Link Here
167
    }
166
    }
168
}
167
}
169
(-)src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (-5 / +5 lines)
Line 274 Link Here
274
    /**
274
    /**
275
     * set the sheet name.
275
     * set the sheet name.
276
     * @param sheet number (0 based)
276
     * @param sheet sheet number (0 based)
277
     * @param sheet name
277
     * @param name sheet name
278
     */
278
     */
279
    public void setSheetName(int sheet, String name)
279
    public void setSheetName(int sheet, String name)
Line 834 Link Here
834
    }
834
    }
835
	/**
835
	/**
836
	 * Sets the printarea for the sheet provided
836
	 * Sets the printarea for the sheet provided.
837
	 * <p>
837
	 * <p>
838
	 * i.e. Reference = $A$1:$B$2
838
	 * i.e. Reference = $A$1:$B$2
839
	 * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
839
	 * @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
Line 858 Link Here
858
	/**
858
	/**
859
	 * For the Convenience of Java Programmers maintaining pointers.
859
	 * For the Convenience of Java Programmers maintaining pointers.
860
	 * @see setPrintArea(int, String)
860
	 * @see #setPrintArea(int, String)
861
	 * @param sheetIndex Zero-based sheet index (0 = First Sheet)
861
	 * @param sheetIndex Zero-based sheet index (0 = First Sheet)
862
	 * @param startColumn Column to begin printarea
862
	 * @param startColumn Column to begin printarea
863
	 * @param endColumn Column to end the printarea
863
	 * @param endColumn Column to end the printarea
Lines 890-891 Link Here
890
		if (name == null) return null;
890
		if (name == null) return null;
891
		//adding one here because 0 indicates a global named region; doesnt make sense for print areas
891
		//adding one here because 0 indicates a global named region; doesnt make sense for print areas
892
		return name.getAreaReference(workbook.getSheetReferences());
892
		return name.getAreaReference(workbook);
893
	}
893
	}
894
    /**
894
    /**
(-)src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (-2 / +1 lines)
Line 56 Link Here
56
import junit.framework.TestCase;
56
import junit.framework.TestCase;
57
import org.apache.poi.hssf.record.formula.*;
57
import org.apache.poi.hssf.record.formula.*;
58
import org.apache.poi.hssf.util.SheetReferences;
59
/**
58
/**
60
 * Test the low level formula parser functionality. High level tests are to
59
 * Test the low level formula parser functionality. High level tests are to
Lines 145-150 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
    }

Return to bug 21444