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

(-)src/java/org/apache/poi/hssf/dev/FormulaViewer.java (-28 / +23 lines)
Lines 82-87 Link Here
82
 * FormulaViewer - finds formulas in a BIFF8 file and attempts to read them/display
82
 * FormulaViewer - finds formulas in a BIFF8 file and attempts to read them/display
83
 * data from them. Only works if Formulas are enabled in "RecordFactory"
83
 * data from them. Only works if Formulas are enabled in "RecordFactory"
84
 * @author  andy
84
 * @author  andy
85
 * @author Avik
85
 */
86
 */
86
87
87
public class FormulaViewer
88
public class FormulaViewer
Lines 132-171 Link Here
132
133
133
    public void parseFormulaRecord(FormulaRecord record)
134
    public void parseFormulaRecord(FormulaRecord record)
134
    {
135
    {
135
        System.out.println("In ParseFormula Record");
136
        System.out.println("==============================");
136
        System.out.println("row   = " + record.getRow());
137
        System.out.print("row = " + record.getRow());
137
        System.out.println("col   = " + record.getColumn());
138
        System.out.println(", col = " + record.getColumn());
138
        System.out.println("value = " + record.getValue());
139
        System.out.println("value = " + record.getValue());
139
        System.out.println("xf    = " + record.getXFIndex());
140
        System.out.print("xf = " + record.getXFIndex());
140
        System.out.println("number of ptgs = "
141
        System.out.print(", number of ptgs = "
141
                           + record.getNumberOfExpressionTokens());
142
                           + record.getNumberOfExpressionTokens());
142
        System.out.println("options = " + record.getOptions());
143
        System.out.println(", options = " + record.getOptions());
143
        System.out.println(composeForumla(record));
144
        System.out.println("RPN List = "+formulaString(record));
145
        System.out.println("Formula text = "+ composeForumla(record));
144
    }
146
    }
145
147
146
    public String composeForumla(FormulaRecord record)
148
    private String formulaString(FormulaRecord record) {
147
    {
148
        StringBuffer formula = new StringBuffer("=");
149
        StringBuffer formula = new StringBuffer("=");
149
        int          numptgs = record.getNumberOfExpressionTokens();
150
        int          numptgs = record.getNumberOfExpressionTokens();
150
        List         ptgs    = record.getParsedExpression();
151
        List         tokens    = record.getParsedExpression();
151
152
        StringBuffer buf = new StringBuffer();
152
        for (int ptgnum = numptgs - 1; ptgnum > (-1); ptgnum--)
153
           for (int i=0;i<numptgs;i++) {
153
        {
154
            buf.append( ( (Ptg)tokens.get(i)).toFormulaString());
154
            Ptg          ptg      = ( Ptg ) ptgs.get(ptgnum);
155
            buf.append(' ');
155
            OperationPtg optg     = ( OperationPtg ) ptg;
156
        } 
156
            int          numops   = optg.getNumberOfOperands();
157
        return buf.toString();
157
            Ptg[]        ops      = new Ptg[ numops ];
158
    }
158
            int          opoffset = 1;
159
    
159
160
    
160
            for (int opnum = ops.length - 1; opnum > -1; opnum--)
161
    private String composeForumla(FormulaRecord record)
161
            {
162
    {
162
                ops[ opnum ] = ( Ptg ) ptgs.get(ptgnum - opoffset);
163
       return  FormulaParser.toFormulaString(record.getParsedExpression());
163
                opoffset++;
164
            }
165
            formula.append(optg.toFormulaString(ops));
166
            ptgnum -= ops.length;
167
        }
168
        return formula.toString();
169
    }
164
    }
170
165
171
    /**
166
    /**
(-)src/java/org/apache/poi/hssf/model/Sheet.java (-2 / +4 lines)
Lines 64-70 Link Here
64
import org.apache.poi.util.POILogFactory;
64
import org.apache.poi.util.POILogFactory;
65
import org.apache.poi.hssf
65
import org.apache.poi.hssf
66
    .record.*;       // normally I don't do this, buy we literally mean ALL
66
    .record.*;       // normally I don't do this, buy we literally mean ALL
67
import org.apache.poi.hssf.record.formula.FormulaUtil;
67
import org.apache.poi.hssf.record.formula.FormulaParser;
68
import org.apache.poi.hssf.record.formula.Ptg;
68
import org.apache.poi.hssf.record.formula.Ptg;
69
import org.apache.poi.util.IntList;
69
import org.apache.poi.util.IntList;
70
import org.apache.poi.util.POILogger;
70
import org.apache.poi.util.POILogger;
Lines 706-712 Link Here
706
        rec.setOptions(( short ) 2);
706
        rec.setOptions(( short ) 2);
707
        rec.setValue(0);
707
        rec.setValue(0);
708
        rec.setXFIndex(( short ) 0x0f);
708
        rec.setXFIndex(( short ) 0x0f);
709
        Ptg[] ptg  = FormulaUtil.parseFormula(formula);
709
        FormulaParser fp = new FormulaParser(formula);
710
        fp.parse();
711
        Ptg[] ptg  = fp.getRPNPtg();
710
        int   size = 0;
712
        int   size = 0;
711
713
712
        for (int k = 0; k < ptg.length; k++)
714
        for (int k = 0; k < ptg.length; k++)
(-)src/java/org/apache/poi/hssf/record/formula/AddPtg.java (-22 / +6 lines)
Lines 78-84 Link Here
78
78
79
    /** Creates new AddPtg */
79
    /** Creates new AddPtg */
80
80
81
    public AddPtg()
81
    protected AddPtg()
82
    {
82
    {
83
    }
83
    }
84
84
Lines 88-97 Link Here
88
        // doesn't need anything
88
        // doesn't need anything
89
    }
89
    }
90
    
90
    
91
    protected AddPtg(String formula, int offset) {
91
   
92
        
93
    }
94
95
    public void writeBytes(byte [] array, int offset)
92
    public void writeBytes(byte [] array, int offset)
96
    {
93
    {
97
        array[ offset + 0 ] = sid;
94
        array[ offset + 0 ] = sid;
Lines 111-142 Link Here
111
    {
108
    {
112
        return 2;
109
        return 2;
113
    }
110
    }
114
111
    
112
    /** Implementation of method from Ptg */
115
    public String toFormulaString()
113
    public String toFormulaString()
116
    {
114
    {
117
        return "+";
115
        return "+";
118
    }
116
    }
119
       
117
       
120
    public String toFormulaString(Ptg [] operands)
118
   /** implementation of method from OperationsPtg*/  
121
    {
122
        StringBuffer buffer = new StringBuffer();
123
124
        buffer.append(operands[ 0 ].toFormulaString());
125
        buffer.append("+");
126
        buffer.append(operands[ 1 ].toFormulaString());
127
        return buffer.toString();
128
    }
129
           
130
    public int getStringLength() {
131
        return 1;
132
    }
133
134
    
135
    public String toFormulaString(String[] operands) {
119
    public String toFormulaString(String[] operands) {
136
        StringBuffer buffer = new StringBuffer();
120
        StringBuffer buffer = new StringBuffer();
137
121
138
        buffer.append(operands[ 0 ]);
122
        buffer.append(operands[ 0 ]);
139
        buffer.append("+");
123
        buffer.append(toFormulaString());
140
        buffer.append(operands[ 1 ]);
124
        buffer.append(operands[ 1 ]);
141
        return buffer.toString();
125
        return buffer.toString();
142
    }
126
    }
(-)src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java (-247 / +494 lines)
Lines 1-247 Link Here
1
1
2
/* ====================================================================
2
3
 * The Apache Software License, Version 1.1
3
/* ====================================================================
4
 *
4
5
 * Copyright (c) 2002 The Apache Software Foundation.  All rights
5
 * The Apache Software License, Version 1.1
6
 * reserved.
6
7
 *
7
 *
8
 * Redistribution and use in source and binary forms, with or without
8
9
 * modification, are permitted provided that the following conditions
9
 * Copyright (c) 2002 The Apache Software Foundation.  All rights
10
 * are met:
10
11
 *
11
 * reserved.
12
 * 1. Redistributions of source code must retain the above copyright
12
13
 *    notice, this list of conditions and the following disclaimer.
13
 *
14
 *
14
15
 * 2. Redistributions in binary form must reproduce the above copyright
15
 * Redistribution and use in source and binary forms, with or without
16
 *    notice, this list of conditions and the following disclaimer in
16
17
 *    the documentation and/or other materials provided with the
17
 * modification, are permitted provided that the following conditions
18
 *    distribution.
18
19
 *
19
 * are met:
20
 * 3. The end-user documentation included with the redistribution,
20
21
 *    if any, must include the following acknowledgment:
21
 *
22
 *       "This product includes software developed by the
22
23
 *        Apache Software Foundation (http://www.apache.org/)."
23
 * 1. Redistributions of source code must retain the above copyright
24
 *    Alternately, this acknowledgment may appear in the software itself,
24
25
 *    if and wherever such third-party acknowledgments normally appear.
25
 *    notice, this list of conditions and the following disclaimer.
26
 *
26
27
 * 4. The names "Apache" and "Apache Software Foundation" and
27
 *
28
 *    "Apache POI" must not be used to endorse or promote products
28
29
 *    derived from this software without prior written permission. For
29
 * 2. Redistributions in binary form must reproduce the above copyright
30
 *    written permission, please contact apache@apache.org.
30
31
 *
31
 *    notice, this list of conditions and the following disclaimer in
32
 * 5. Products derived from this software may not be called "Apache",
32
33
 *    "Apache POI", nor may "Apache" appear in their name, without
33
 *    the documentation and/or other materials provided with the
34
 *    prior written permission of the Apache Software Foundation.
34
35
 *
35
 *    distribution.
36
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36
37
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37
 *
38
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38
39
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39
 * 3. The end-user documentation included with the redistribution,
40
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
41
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41
 *    if any, must include the following acknowledgment:
42
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42
43
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43
 *       "This product includes software developed by the
44
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44
45
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45
 *        Apache Software Foundation (http://www.apache.org/)."
46
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46
47
 * SUCH DAMAGE.
47
 *    Alternately, this acknowledgment may appear in the software itself,
48
 * ====================================================================
48
49
 *
49
 *    if and wherever such third-party acknowledgments normally appear.
50
 * This software consists of voluntary contributions made by many
50
51
 * individuals on behalf of the Apache Software Foundation.  For more
51
 *
52
 * information on the Apache Software Foundation, please see
52
53
 * <http://www.apache.org/>.
53
 * 4. The names "Apache" and "Apache Software Foundation" and
54
 */
54
55
55
 *    "Apache POI" must not be used to endorse or promote products
56
package org.apache.poi.hssf.record.formula;
56
57
57
 *    derived from this software without prior written permission. For
58
import org.apache.poi.util.LittleEndian;
58
59
import org.apache.poi.hssf.util.RangeAddress;
59
 *    written permission, please contact apache@apache.org.
60
60
61
/**
61
 *
62
 * Title:        Area 3D Ptg - 3D referecnce (Sheet + Area)<P>
62
63
 * Description:  Defined a area in Extern Sheet. <P>
63
 * 5. Products derived from this software may not be called "Apache",
64
 * REFERENCE:  <P>
64
65
 * @author Libin Roman (Vista Portal LDT. Developer)
65
 *    "Apache POI", nor may "Apache" appear in their name, without
66
 * @version 1.0-pre
66
67
 */
67
 *    prior written permission of the Apache Software Foundation.
68
68
69
public class Area3DPtg extends Ptg
69
 *
70
{
70
71
    public final static short sid  = 0x3b;
71
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
72
    private final static int  SIZE = 11; // 10 + 1 for Ptg
72
73
    private short             field_1_index_extern_sheet;  
73
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
74
    private short             field_2_first_row;
74
75
    private short             field_3_last_row;
75
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
76
    private short             field_4_first_column;
76
77
    private short             field_5_last_column;
77
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
78
78
79
    /** Creates new AreaPtg */
79
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
80
80
81
    public Area3DPtg()
81
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
82
    {
82
83
    }
83
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
84
84
85
    public Area3DPtg(byte[] data, int offset)
85
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
86
    {
86
87
        offset++;
87
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
88
        field_1_index_extern_sheet = LittleEndian.getShort(data, 0 + offset);
88
89
        field_2_first_row          = LittleEndian.getShort(data, 2 + offset);
89
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
90
        field_3_last_row           = LittleEndian.getShort(data, 4 + offset);
90
91
        field_4_first_column       = LittleEndian.getShort(data, 6 + offset);
91
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92
        field_5_last_column        = LittleEndian.getShort(data, 8 + offset);
92
93
    }
93
 * SUCH DAMAGE.
94
94
95
    public String toString()
95
 * ====================================================================
96
    {
96
97
        StringBuffer buffer = new StringBuffer();
97
 *
98
98
99
        buffer.append("AreaPtg\n");
99
 * This software consists of voluntary contributions made by many
100
        buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n");
100
101
        buffer.append("firstRow = " + getFirstRow()).append("\n");
101
 * individuals on behalf of the Apache Software Foundation.  For more
102
        buffer.append("lastRow  = " + getLastRow()).append("\n");
102
103
        buffer.append("firstCol = " + getFirstColumn()).append("\n");
103
 * information on the Apache Software Foundation, please see
104
        buffer.append("lastCol  = " + getLastColumn()).append("\n");
104
105
        buffer.append("firstColRowRel= "
105
 * <http://www.apache.org/>.
106
                      + isFirstColRowRelative()).append("\n");
106
107
        buffer.append("lastColRowRel = "
107
 */
108
                      + isLastColRowRelative()).append("\n");
108
109
        buffer.append("firstColRel   = " + isFirstColRelative()).append("\n");
109
110
        buffer.append("lastColRel    = " + isLastColRelative()).append("\n");
110
111
        return buffer.toString();
111
package org.apache.poi.hssf.record.formula;
112
    }
112
113
113
114
    public void writeBytes(byte [] array, int offset)
114
115
    {
115
import org.apache.poi.util.LittleEndian;
116
        array[ 0 + offset ] = sid;
116
117
        LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
117
import org.apache.poi.hssf.util.RangeAddress;
118
        LittleEndian.putShort(array, 3 + offset , getFirstRow());
118
119
        LittleEndian.putShort(array, 5 + offset , getLastRow());               
119
120
        LittleEndian.putShort(array, 7 + offset , getFirstColumnRaw());               
120
121
        LittleEndian.putShort(array, 9 + offset , getLastColumnRaw());               
121
/**
122
    }
122
123
123
 * Title:        Area 3D Ptg - 3D referecnce (Sheet + Area)<P>
124
    public int getSize()
124
125
    {
125
 * Description:  Defined a area in Extern Sheet. <P>
126
        return SIZE;
126
127
    }
127
 * REFERENCE:  <P>
128
    
128
129
    public short getExternSheetIndex(){
129
 * @author Libin Roman (Vista Portal LDT. Developer)
130
        return field_1_index_extern_sheet;
130
131
    }
131
 * @version 1.0-pre
132
    
132
133
    public void setExternSheetIndex(short index){
133
 */
134
        field_1_index_extern_sheet = index;
134
135
    }
135
136
136
137
    public short getFirstRow()
137
public class Area3DPtg extends Ptg
138
    {
138
139
        return field_2_first_row;
139
{
140
    }
140
141
141
    public final static short sid  = 0x3b;
142
    public void setFirstRow(short row)
142
143
    {
143
    private final static int  SIZE = 11; // 10 + 1 for Ptg
144
        field_2_first_row = row;
144
145
    }
145
    private short             field_1_index_extern_sheet;  
146
146
147
    public short getLastRow()
147
    private short             field_2_first_row;
148
    {
148
149
        return field_3_last_row;
149
    private short             field_3_last_row;
150
    }
150
151
151
    private short             field_4_first_column;
152
    public void setLastRow(short row)
152
153
    {
153
    private short             field_5_last_column;
154
        field_3_last_row = row;
154
155
    }
155
156
156
157
    public short getFirstColumn()
157
    /** Creates new AreaPtg */
158
    {
158
   
159
        return ( short ) (field_4_first_column & 0xFF);
159
    public Area3DPtg() {
160
    }
160
 
161
161
    }
162
    public short getFirstColumnRaw()
162
163
    {
163
   
164
        return field_4_first_column;
164
165
    }
165
166
166
167
    public boolean isFirstColRowRelative()
167
    public Area3DPtg(byte[] data, int offset)
168
    {
168
169
        return (((getFirstColumnRaw()) & 0x8000) == 0x8000);
169
    {
170
    }
170
171
171
        offset++;
172
    public boolean isFirstColRelative()
172
173
    {
173
        field_1_index_extern_sheet = LittleEndian.getShort(data, 0 + offset);
174
        return (((getFirstColumnRaw()) & 0x4000) == 0x4000);
174
175
    }
175
        field_2_first_row          = LittleEndian.getShort(data, 2 + offset);
176
176
177
    public void setFirstColumn(short column)
177
        field_3_last_row           = LittleEndian.getShort(data, 4 + offset);
178
    {
178
179
        field_4_first_column &= 0xFF00;
179
        field_4_first_column       = LittleEndian.getShort(data, 6 + offset);
180
        field_4_first_column |= column & 0xFF; 
180
181
    }
181
        field_5_last_column        = LittleEndian.getShort(data, 8 + offset);
182
182
183
    public void setFirstColumnRaw(short column)
183
    }
184
    {
184
185
        field_4_first_column = column;   
185
    protected Area3DPtg(String areaRef) {
186
    }
186
        //TODO!
187
187
    }
188
    public short getLastColumn()
188
189
    {
189
    public String toString()
190
        return ( short ) (field_5_last_column & 0xFF);   
190
191
    }
191
    {
192
192
193
    public short getLastColumnRaw()
193
        StringBuffer buffer = new StringBuffer();
194
    {
194
195
        return field_5_last_column;
195
196
    }
196
197
197
        buffer.append("AreaPtg\n");
198
    public boolean isLastColRowRelative()
198
199
    {
199
        buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n");
200
        return (((getLastColumnRaw()) & 0x8000) == 1);
200
201
    }
201
        buffer.append("firstRow = " + getFirstRow()).append("\n");
202
202
203
    public boolean isLastColRelative()
203
        buffer.append("lastRow  = " + getLastRow()).append("\n");
204
    {
204
205
        return (((getFirstColumnRaw()) & 0x4000) == 1);
205
        buffer.append("firstCol = " + getFirstColumn()).append("\n");
206
    }
206
207
207
        buffer.append("lastCol  = " + getLastColumn()).append("\n");
208
    public void setLastColumn(short column)
208
209
    {
209
        buffer.append("firstColRowRel= "
210
        field_5_last_column &= 0xFF00;
210
211
        field_5_last_column |= column & 0xFF; 
211
                      + isFirstColRowRelative()).append("\n");
212
    }
212
213
213
        buffer.append("lastColRowRel = "
214
    public void setLastColumnRaw(short column)
214
215
    {
215
                      + isLastColRowRelative()).append("\n");
216
        field_5_last_column = column;
216
217
    }
217
        buffer.append("firstColRel   = " + isFirstColRelative()).append("\n");
218
    
218
219
    public String getArea(){
219
        buffer.append("lastColRel    = " + isLastColRelative()).append("\n");
220
        RangeAddress ra = new RangeAddress( getFirstColumn(),getFirstRow() + 1, getLastColumn(), getLastRow() + 1);   
220
221
        String result = ra.getAddress();
221
        return buffer.toString();
222
        
222
223
        return result;
223
    }
224
    }
224
225
    
225
226
    public void setArea(String ref){
226
227
        RangeAddress ra = new RangeAddress(ref);
227
    public void writeBytes(byte [] array, int offset)
228
        
228
229
        String from = ra.getFromCell();
229
    {
230
        String to   = ra.getToCell();
230
231
        
231
        array[ 0 + offset ] = sid;
232
        setFirstColumn((short) (ra.getXPosition(from) -1));
232
233
        setFirstRow((short) (ra.getYPosition(from) -1));
233
        LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
234
        setLastColumn((short) (ra.getXPosition(to) -1));
234
235
        setLastRow((short) (ra.getYPosition(to) -1));
235
        LittleEndian.putShort(array, 3 + offset , getFirstRow());
236
                        
236
237
    }
237
        LittleEndian.putShort(array, 5 + offset , getLastRow());               
238
238
239
    public String toFormulaString()
239
        LittleEndian.putShort(array, 7 + offset , getFirstColumnRaw());               
240
    {
240
241
        String result = getArea();
241
        LittleEndian.putShort(array, 9 + offset , getLastColumnRaw());               
242
242
243
        return result;
243
    }
244
    }
244
245
245
246
    
246
247
}
247
    public int getSize()
248
249
    {
250
251
        return SIZE;
252
253
    }
254
255
    
256
257
    public short getExternSheetIndex(){
258
259
        return field_1_index_extern_sheet;
260
261
    }
262
263
    
264
265
    public void setExternSheetIndex(short index){
266
267
        field_1_index_extern_sheet = index;
268
269
    }
270
271
272
273
    public short getFirstRow()
274
275
    {
276
277
        return field_2_first_row;
278
279
    }
280
281
282
283
    public void setFirstRow(short row)
284
285
    {
286
287
        field_2_first_row = row;
288
289
    }
290
291
292
293
    public short getLastRow()
294
295
    {
296
297
        return field_3_last_row;
298
299
    }
300
301
302
303
    public void setLastRow(short row)
304
305
    {
306
307
        field_3_last_row = row;
308
309
    }
310
311
312
313
    public short getFirstColumn()
314
315
    {
316
317
        return ( short ) (field_4_first_column & 0xFF);
318
319
    }
320
321
322
323
    public short getFirstColumnRaw()
324
325
    {
326
327
        return field_4_first_column;
328
329
    }
330
331
332
333
    public boolean isFirstColRowRelative()
334
335
    {
336
337
        return (((getFirstColumnRaw()) & 0x8000) == 0x8000);
338
339
    }
340
341
342
343
    public boolean isFirstColRelative()
344
345
    {
346
347
        return (((getFirstColumnRaw()) & 0x4000) == 0x4000);
348
349
    }
350
351
352
353
    public void setFirstColumn(short column)
354
355
    {
356
357
        field_4_first_column &= 0xFF00;
358
359
        field_4_first_column |= column & 0xFF; 
360
361
    }
362
363
364
365
    public void setFirstColumnRaw(short column)
366
367
    {
368
369
        field_4_first_column = column;   
370
371
    }
372
373
374
375
    public short getLastColumn()
376
377
    {
378
379
        return ( short ) (field_5_last_column & 0xFF);   
380
381
    }
382
383
384
385
    public short getLastColumnRaw()
386
387
    {
388
389
        return field_5_last_column;
390
391
    }
392
393
394
395
    public boolean isLastColRowRelative()
396
397
    {
398
399
        return (((getLastColumnRaw()) & 0x8000) == 1);
400
401
    }
402
403
404
405
    public boolean isLastColRelative()
406
407
    {
408
409
        return (((getFirstColumnRaw()) & 0x4000) == 1);
410
411
    }
412
413
414
415
    public void setLastColumn(short column)
416
417
    {
418
419
        field_5_last_column &= 0xFF00;
420
421
        field_5_last_column |= column & 0xFF; 
422
423
    }
424
425
426
427
    public void setLastColumnRaw(short column)
428
429
    {
430
431
        field_5_last_column = column;
432
433
    }
434
435
    
436
437
    public String getArea(){
438
439
        RangeAddress ra = new RangeAddress( getFirstColumn(),getFirstRow() + 1, getLastColumn(), getLastRow() + 1);   
440
441
        String result = ra.getAddress();
442
443
        
444
445
        return result;
446
447
    }
448
449
    
450
451
    public void setArea(String ref){
452
453
        RangeAddress ra = new RangeAddress(ref);
454
455
        
456
457
        String from = ra.getFromCell();
458
459
        String to   = ra.getToCell();
460
461
        
462
463
        setFirstColumn((short) (ra.getXPosition(from) -1));
464
465
        setFirstRow((short) (ra.getYPosition(from) -1));
466
467
        setLastColumn((short) (ra.getXPosition(to) -1));
468
469
        setLastRow((short) (ra.getYPosition(to) -1));
470
471
                        
472
473
    }
474
475
476
477
    public String toFormulaString()
478
479
    {
480
481
        String result = getArea();
482
483
484
485
        return result;
486
487
    }
488
489
490
491
    
492
493
}
494
(-)src/java/org/apache/poi/hssf/record/formula/AreaPtg.java (-7 / +2 lines)
Lines 85-97 Link Here
85
    private BitField         column      = new BitField(0x3FFF);
85
    private BitField         column      = new BitField(0x3FFF);
86
86
87
    
87
    
88
    /** Creates new AreaPtg */
88
   
89
89
    protected AreaPtg(String arearef) {
90
    public AreaPtg()
91
    {
92
    }
93
    
94
    public AreaPtg(String arearef) {
95
        int[] xyxy = ReferenceUtil.getXYXYFromAreaRef(arearef);
90
        int[] xyxy = ReferenceUtil.getXYXYFromAreaRef(arearef);
96
        setFirstRow((short)xyxy[0]);
91
        setFirstRow((short)xyxy[0]);
97
        setFirstColumn((short)xyxy[1]);
92
        setFirstColumn((short)xyxy[1]);
(-)src/java/org/apache/poi/hssf/record/formula/AttrPtg.java (-13 / +3 lines)
Lines 87-98 Link Here
87
    private BitField          baxcel       = new BitField(0x20);
87
    private BitField          baxcel       = new BitField(0x20);
88
    private BitField          space        = new BitField(0x40);
88
    private BitField          space        = new BitField(0x40);
89
89
90
    /** Creates new AttrPtg */
90
    public AttrPtg() {
91
92
    public AttrPtg()
93
    {
94
    }
91
    }
95
92
    
96
    public AttrPtg(byte [] data, int offset)
93
    public AttrPtg(byte [] data, int offset)
97
    {
94
    {
98
        offset++;   // adjust past id
95
        offset++;   // adjust past id
Lines 199-209 Link Here
199
        return "SUM()";
196
        return "SUM()";
200
    }
197
    }
201
198
202
    public String toFormulaString(Ptg [] operands)
203
    {
204
        return "SUM(" + operands[ 0 ].toFormulaString() + ")";
205
    }
206
207
    public int getNumberOfOperands()
199
    public int getNumberOfOperands()
208
    {
200
    {
209
        return 1;
201
        return 1;
Lines 218-225 Link Here
218
        return "SUM(" + operands[ 0 ] + ")";
210
        return "SUM(" + operands[ 0 ] + ")";
219
    }    
211
    }    
220
    
212
    
221
    public int getPrecedence() {
213
 
222
        return 1;
223
    }    
224
    
214
    
225
}
215
}
(-)src/java/org/apache/poi/hssf/record/formula/ConcatPtg.java (-22 / +2 lines)
Lines 75-93 Link Here
75
    
75
    
76
    private final static String CONCAT = "&";
76
    private final static String CONCAT = "&";
77
77
78
    /** Creates new ConcatPtg */
79
80
    public ConcatPtg()
81
    {
82
    }
83
84
    public ConcatPtg(byte [] data, int offset)
78
    public ConcatPtg(byte [] data, int offset)
85
    {
79
    {
86
80
87
        // doesn't need anything
81
        // doesn't need anything
88
    }
82
    }
89
    
83
    
90
    protected ConcatPtg(String formula, int offset) {
84
    protected ConcatPtg() {
91
        
85
        
92
    }
86
    }
93
87
Lines 116-136 Link Here
116
        return CONCAT;
110
        return CONCAT;
117
    }    
111
    }    
118
112
119
    public String toFormulaString(Ptg [] operands)
113
       
120
    {
121
        StringBuffer buffer = new StringBuffer();
122
123
        buffer.append(operands[ 0 ].toFormulaString());
124
        buffer.append(CONCAT);
125
        buffer.append(operands[ 1 ].toFormulaString());
126
        return buffer.toString();
127
    }
128
           
129
    public int getStringLength() {
130
        return 1;
131
    }
132
133
    
134
    public String toFormulaString(String[] operands) {
114
    public String toFormulaString(String[] operands) {
135
        StringBuffer buffer = new StringBuffer();
115
        StringBuffer buffer = new StringBuffer();
136
116
(-)src/java/org/apache/poi/hssf/record/formula/DividePtg.java (-17 / +3 lines)
Lines 75-81 Link Here
75
75
76
    /** Creates new AddPtg */
76
    /** Creates new AddPtg */
77
77
78
    public DividePtg()
78
    protected DividePtg()
79
    {
79
    {
80
    }
80
    }
81
81
Lines 110-134 Link Here
110
        return "/";
110
        return "/";
111
    }
111
    }
112
112
113
    public String toFormulaString(Ptg [] operands)
113
     public String toFormulaString(String[] operands) {
114
    {
115
        StringBuffer buffer = new StringBuffer();
116
117
        buffer.append(operands[ 0 ].toFormulaString());
118
        buffer.append("/");
119
        buffer.append(operands[ 1 ].toFormulaString());
120
        return buffer.toString();
121
    }
122
   
123
    public int getStringLength() {
124
        return 1;
125
    }
126
    
127
    public String toFormulaString(String[] operands) {
128
        StringBuffer buffer = new StringBuffer();
114
        StringBuffer buffer = new StringBuffer();
129
115
130
        buffer.append(operands[ 0 ]);
116
        buffer.append(operands[ 0 ]);
131
        buffer.append("/");
117
        buffer.append(toFormulaString());
132
        buffer.append(operands[ 1 ]);
118
        buffer.append(operands[ 1 ]);
133
        return buffer.toString();
119
        return buffer.toString();
134
    }      
120
    }      
(-)src/java/org/apache/poi/hssf/record/formula/ExpPtg.java (-1 / +1 lines)
Lines 73-79 Link Here
73
73
74
    /** Creates new ExpPtg */
74
    /** Creates new ExpPtg */
75
75
76
    public ExpPtg()
76
    protected ExpPtg()
77
    {
77
    {
78
    }
78
    }
79
79
(-)src/java/org/apache/poi/hssf/record/formula/FormulaParser.java (-4 / +3 lines)
Lines 310-317 Link Here
310
                if (IsDigit(Look)) number = number +"."+ GetNum(); //this also takes care of someone entering "1234."
310
                if (IsDigit(Look)) number = number +"."+ GetNum(); //this also takes care of someone entering "1234."
311
                tokens.add(new NumberPtg(number));
311
                tokens.add(new NumberPtg(number));
312
            } else {
312
            } else {
313
                //IntPtg p = new IntPtg(GetNum());   // removing since a ptg should be able to create itself from parser results. 
314
                //p.setValue(Short.parseShort(GetNum()));
315
                tokens.add(new IntPtg(number));  //TODO:what if the number is too big to be a short? ..add factory to return Int or Number!
313
                tokens.add(new IntPtg(number));  //TODO:what if the number is too big to be a short? ..add factory to return Int or Number!
316
            }
314
            }
317
        }
315
        }
Lines 450-456 Link Here
450
    
448
    
451
    /** Static method to convert an array of Ptgs in RPN order 
449
    /** Static method to convert an array of Ptgs in RPN order 
452
     *  to a human readable string format in infix mode
450
     *  to a human readable string format in infix mode
453
     *  TODO - extra brackets might appear, but string will be semantically correct. 
454
     */
451
     */
455
    public static String toFormulaString(Ptg[] ptgs) {
452
    public static String toFormulaString(Ptg[] ptgs) {
456
        java.util.Stack stack = new java.util.Stack();
453
        java.util.Stack stack = new java.util.Stack();
Lines 468-474 Link Here
468
                    
465
                    
469
                }  
466
                }  
470
                String result = o.toFormulaString(operands);
467
                String result = o.toFormulaString(operands);
471
                //if (! (o instanceof DummyFunctionPtg) ) result = "("+result+")" ;
472
                stack.push(result);
468
                stack.push(result);
473
            } else {
469
            } else {
474
                stack.push(ptgs[i].toFormulaString());
470
                stack.push(ptgs[i].toFormulaString());
Lines 477-482 Link Here
477
        return (String) stack.pop(); //TODO: catch stack underflow and throw parse exception. 
473
        return (String) stack.pop(); //TODO: catch stack underflow and throw parse exception. 
478
    }
474
    }
479
   
475
   
476
    /** toString on the parser instance returns the RPN ordered list of tokens
477
     *   Useful for testing
478
     */
480
    public String toString() {
479
    public String toString() {
481
        StringBuffer buf = new StringBuffer();
480
        StringBuffer buf = new StringBuffer();
482
           for (int i=0;i<tokens.size();i++) {
481
           for (int i=0;i<tokens.size();i++) {
(-)src/java/org/apache/poi/hssf/record/formula/FunctionPtg.java (-20 / +10 lines)
Lines 16-27 Link Here
16
    private byte field_1_num_args;
16
    private byte field_1_num_args;
17
    private short field_2_fnc_index;
17
    private short field_2_fnc_index;
18
    
18
    
19
    //private String name;
19
        
20
    //private int numOperands;
20
    /**Creates new function pointer from a byte array 
21
    /** Creates new DummyFunctionPtg */
21
     * usually called while reading an excel file. 
22
    public FunctionPtg() {
22
     */
23
    }
24
    
25
    public FunctionPtg(byte[] data, int offset) {
23
    public FunctionPtg(byte[] data, int offset) {
26
        offset++;
24
        offset++;
27
        field_1_num_args = data[ offset + 0 ];
25
        field_1_num_args = data[ offset + 0 ];
Lines 29-36 Link Here
29
        
27
        
30
    }
28
    }
31
    
29
    
32
    
30
    /**
33
    public FunctionPtg(String pName, byte pNumOperands) {
31
     * Create a function ptg from a string tokenised by the parser
32
     */
33
    protected FunctionPtg(String pName, byte pNumOperands) {
34
        field_1_num_args = pNumOperands;
34
        field_1_num_args = pNumOperands;
35
        field_2_fnc_index = lookupIndex(pName);
35
        field_2_fnc_index = lookupIndex(pName);
36
        
36
        
Lines 64-83 Link Here
64
    }
64
    }
65
    
65
    
66
    public String toFormulaString() {
66
    public String toFormulaString() {
67
        return getName()+getNumberOfOperands();
67
        return getName();
68
    }
69
    
70
    public String toFormulaString(Ptg[] operands) {
71
        StringBuffer buf = new StringBuffer();
72
        buf.append(getName()+"(");
73
        for (int i=0;i<operands.length;i++) {
74
            buf.append(operands[i].toFormulaString()).append(',');
75
        }
76
        buf.append(")");
77
        return buf.toString();
78
    }
68
    }
79
    
69
    
80
     public String toFormulaString(String[] operands) {
70
    public String toFormulaString(String[] operands) {
81
        StringBuffer buf = new StringBuffer();
71
        StringBuffer buf = new StringBuffer();
82
        buf.append(getName()+"(");
72
        buf.append(getName()+"(");
83
        if (operands.length >0) {
73
        if (operands.length >0) {
(-)src/java/org/apache/poi/hssf/record/formula/IntPtg.java (-45 / +1 lines)
Lines 77-99 Link Here
77
77
78
    private String val;
78
    private String val;
79
    private int strlen = 0;
79
    private int strlen = 0;
80
    /** Creates new IntPtg */
80
  
81
82
    public IntPtg()
83
    {
84
    }
85
86
    public IntPtg(byte [] data, int offset)
81
    public IntPtg(byte [] data, int offset)
87
    {
82
    {
88
        setValue(LittleEndian.getShort(data, offset + 1));
83
        setValue(LittleEndian.getShort(data, offset + 1));
89
    }
84
    }
90
    
85
    
91
    protected IntPtg(String formula, int offset) {
92
        val = parseString(formula, offset);
93
        if (val == null) throw new RuntimeException("WHOOAA there...thats got no int!");
94
        strlen=val.length();
95
        field_1_value = Short.parseShort(val);
96
    }
97
    
86
    
98
    // IntPtg should be able to create itself, shouldnt have to call setValue
87
    // IntPtg should be able to create itself, shouldnt have to call setValue
99
    protected IntPtg(String formulaToken) {
88
    protected IntPtg(String formulaToken) {
Lines 126-162 Link Here
126
        return "" + getValue();
115
        return "" + getValue();
127
    }
116
    }
128
    
117
    
129
    private static String parseString(String formula, int pos) {
130
        String retval = null;
131
        while (pos < formula.length() && Character.isWhitespace(formula.charAt(pos))) {
132
            pos++;
133
        }
134
        
135
        if (pos < formula.length()) {
136
            if (Character.isDigit(formula.charAt(pos)) ) {
137
                int numpos = pos;
138
                
139
                while (numpos < formula.length() && Character.isDigit(formula.charAt(numpos))){
140
                    numpos++;
141
                }
142
                
143
                if (numpos == formula.length() || formula.charAt(numpos) != '.') {
144
                    String numberstr = formula.substring(pos,numpos);
145
                    try {
146
                        int number = Short.parseShort(numberstr);
147
                        retval = numberstr;
148
                    } catch (NumberFormatException e) {
149
                        retval = null;
150
                    }
151
                }
152
            }
153
        }
154
        return retval;
155
        
156
    }
157
    
158
        
159
    public int getStringLength() {
160
        return strlen;
161
    }    
162
}
118
}
(-)src/java/org/apache/poi/hssf/record/formula/MultiplyPtg.java (-7 / +2 lines)
Lines 77-83 Link Here
77
77
78
    /** Creates new AddPtg */
78
    /** Creates new AddPtg */
79
79
80
    public MultiplyPtg()
80
    protected MultiplyPtg()
81
    {
81
    {
82
    }
82
    }
83
83
Lines 87-97 Link Here
87
        // doesn't need anything
87
        // doesn't need anything
88
    }
88
    }
89
    
89
    
90
    protected MultiplyPtg(String formula, int offset) {
91
        
92
    }
93
    
94
95
    public void writeBytes(byte [] array, int offset)
90
    public void writeBytes(byte [] array, int offset)
96
    {
91
    {
97
        array[ offset + 0 ] = sid;
92
        array[ offset + 0 ] = sid;
Lines 136-142 Link Here
136
        StringBuffer buffer = new StringBuffer();
131
        StringBuffer buffer = new StringBuffer();
137
132
138
        buffer.append(operands[ 0 ]);
133
        buffer.append(operands[ 0 ]);
139
        buffer.append("*");
134
        buffer.append(toFormulaString());
140
        buffer.append(operands[ 1 ]);
135
        buffer.append(operands[ 1 ]);
141
        return buffer.toString();
136
        return buffer.toString();
142
    }                  
137
    }                  
(-)src/java/org/apache/poi/hssf/record/formula/NamePtg.java (-1 / +2 lines)
Lines 78-85 Link Here
78
78
79
    /** Creates new NamePtg */
79
    /** Creates new NamePtg */
80
80
81
    public NamePtg()
81
    protected NamePtg(String name)
82
    {
82
    {
83
        //TODO
83
    }
84
    }
84
85
85
    /** Creates new NamePtg */
86
    /** Creates new NamePtg */
(-)src/java/org/apache/poi/hssf/record/formula/NumberPtg.java (-15 / +15 lines)
Lines 57-64 Link Here
57
import org.apache.poi.util.LittleEndian;
57
import org.apache.poi.util.LittleEndian;
58
58
59
/**
59
/**
60
 * Integer (short intger)
60
 * Number
61
 * Stores a (java) short value in a formula
61
 * Stores a floating point value in a formula
62
 * value stored in a 8 byte field using IEEE notation
62
 * @author  Avik Sengupta
63
 * @author  Avik Sengupta
63
 */
64
 */
64
65
Lines 69-93 Link Here
69
    public final static byte sid  = 0x1f;
70
    public final static byte sid  = 0x1f;
70
    private double            field_1_value;
71
    private double            field_1_value;
71
72
72
    /** Creates new NumberPtg */
73
        
73
74
    /** Create a NumberPtg from a byte array read from disk */
74
    public NumberPtg()
75
    {
76
    }
77
78
    public NumberPtg(byte [] data, int offset)
75
    public NumberPtg(byte [] data, int offset)
79
    {
76
    {
80
        setValue(LittleEndian.getDouble(data, offset + 1));
77
        setValue(LittleEndian.getDouble(data, offset + 1));
81
    }
78
    }
82
    
79
    
80
    /** Create a NumberPtg from a string representation of  the number
81
     *  Number format is not checked, it is expected to be validated in the parser
82
     *   that calls this method. 
83
     *  @param value : String representation of a floating point number
84
     */
83
    protected NumberPtg(String value) {
85
    protected NumberPtg(String value) {
84
        setValue(Double.parseDouble(value));
86
        setValue(Double.parseDouble(value));
85
    }
87
    }
88
    
89
    
86
    public void setValue(double value)
90
    public void setValue(double value)
87
    {
91
    {
88
        field_1_value = value;
92
        field_1_value = value;
89
    }
93
    }
90
94
    
95
    
91
    public double getValue()
96
    public double getValue()
92
    {
97
    {
93
        return field_1_value;
98
        return field_1_value;
Lines 108-118 Link Here
108
    {
113
    {
109
        return "" + getValue();
114
        return "" + getValue();
110
    }
115
    }
111
    
116
       
112
    
113
    //TODO: do we really need this method??    
114
    public int getStringLength() {
115
        return 1;
116
    }    
117
}
117
}
118
118
(-)src/java/org/apache/poi/hssf/record/formula/OperationPtg.java (-3 / +9 lines)
Lines 75-85 Link Here
75
75
76
    public abstract int getType();
76
    public abstract int getType();
77
    
77
    
78
    /**
79
     *  returns a string representation of the operations
80
     *  the length of the input array should equal the number returned by 
81
     *  @see getNumberOfOperands
82
     *  
83
     */
78
    public abstract String toFormulaString(String[] operands);
84
    public abstract String toFormulaString(String[] operands);
79
    
85
    
86
    /**
87
     * The number of operands expected by the operations
88
     */
80
    public abstract int getNumberOfOperands();
89
    public abstract int getNumberOfOperands();
81
    
82
83
    public abstract String toFormulaString(Ptg [] operands);
84
    
90
    
85
}
91
}
(-)src/java/org/apache/poi/hssf/record/formula/ParenthesisPtg.java (-10 / +3 lines)
Lines 72-78 Link Here
72
    private final static int SIZE = 1;
72
    private final static int SIZE = 1;
73
    public final static byte sid  = 0x15;
73
    public final static byte sid  = 0x15;
74
   
74
   
75
    public ParenthesisPtg()
75
    protected ParenthesisPtg()
76
    {
76
    {
77
    }
77
    }
78
78
Lines 82-91 Link Here
82
        // doesn't need anything
82
        // doesn't need anything
83
    }
83
    }
84
    
84
    
85
    protected ParenthesisPtg(String formula, int offset) {
85
  
86
        
87
    }
88
89
    
86
    
90
    public void writeBytes(byte [] array, int offset)
87
    public void writeBytes(byte [] array, int offset)
91
    {
88
    {
Lines 112-122 Link Here
112
        return "()";
109
        return "()";
113
    }
110
    }
114
111
115
    public String toFormulaString(Ptg [] operands)
112
          
116
    {
117
        return "";
118
    }
119
        
120
    public String toFormulaString(String[] operands) {
113
    public String toFormulaString(String[] operands) {
121
        return "("+operands[0]+")";
114
        return "("+operands[0]+")";
122
    }    
115
    }    
(-)src/java/org/apache/poi/hssf/record/formula/PowerPtg.java (-13 / +3 lines)
Lines 75-81 Link Here
75
75
76
    /** Creates new AddPtg */
76
    /** Creates new AddPtg */
77
77
78
    public PowerPtg()
78
   protected PowerPtg()
79
    {
79
    {
80
    }
80
    }
81
81
Lines 110-133 Link Here
110
        return "^";
110
        return "^";
111
    }
111
    }
112
    
112
    
113
    public String toFormulaString(Ptg [] operands)
113
          
114
    {
115
        StringBuffer buffer = new StringBuffer();
116
117
        buffer.append(operands[ 0 ].toFormulaString());
118
        buffer.append("^");
119
        buffer.append(operands[ 1 ].toFormulaString());        
120
        
121
        return buffer.toString();
122
    }
123
        
124
    
114
    
125
    public String toFormulaString(String[] operands) {
115
    public String toFormulaString(String[] operands) {
126
         StringBuffer buffer = new StringBuffer();
116
         StringBuffer buffer = new StringBuffer();
127
117
128
        
118
        
129
        buffer.append(operands[ 0 ]);
119
        buffer.append(operands[ 0 ]);
130
        buffer.append("^");
120
        buffer.append(toFormulaString());
131
        buffer.append(operands[ 1 ]);
121
        buffer.append(operands[ 1 ]);
132
        return buffer.toString();
122
        return buffer.toString();
133
    }       
123
    }       
(-)src/java/org/apache/poi/hssf/record/formula/Ptg.java (-8 / +6 lines)
Lines 77-83 Link Here
77
     * @param infixPtgs List of ptgs in infix order
77
     * @param infixPtgs List of ptgs in infix order
78
     */
78
     */
79
    
79
    
80
    /* DO NOI REMOVE
80
    /* DO NOT REMOVE
81
     *we keep this method in case we wish to change the way we parse
81
     *we keep this method in case we wish to change the way we parse
82
     *It needs a getPrecedence in OperationsPtg
82
     *It needs a getPrecedence in OperationsPtg
83
    
83
    
Lines 287-301 Link Here
287
        writeBytes(bytes, 0);
287
        writeBytes(bytes, 0);
288
        return bytes;
288
        return bytes;
289
    }
289
    }
290
290
    /** write this Ptg to a byte array*/
291
    public abstract void writeBytes(byte [] array, int offset);
291
    public abstract void writeBytes(byte [] array, int offset);
292
293
    public abstract String toFormulaString();
294
       
295
    public int getStringLength() {
296
        return 0;
297
    }
298
    
292
    
293
    /**
294
     * return a string representation of this token alone
295
     */
296
    public abstract String toFormulaString();
299
    /**
297
    /**
300
     * dump a debug representation (hexdump) to a strnig
298
     * dump a debug representation (hexdump) to a strnig
301
     */
299
     */
(-)src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java (-6 / +2 lines)
Lines 82-98 Link Here
82
    private BitField         rowRelative = new BitField(0x8000);
82
    private BitField         rowRelative = new BitField(0x8000);
83
    private BitField         colRelative = new BitField(0x4000);
83
    private BitField         colRelative = new BitField(0x4000);
84
84
85
    /** Creates new ValueReferencePtg */
85
    
86
87
    public ReferencePtg()
88
    {
89
    }
90
    
86
    
91
    /**
87
    /**
92
     * Takes in a String represnetation of a cell reference and fills out the 
88
     * Takes in a String represnetation of a cell reference and fills out the 
93
     * numeric fields.
89
     * numeric fields.
94
     */
90
     */
95
    public ReferencePtg(String cellref) {
91
    protected ReferencePtg(String cellref) {
96
        int[] xy = ReferenceUtil.getXYFromReference(cellref);
92
        int[] xy = ReferenceUtil.getXYFromReference(cellref);
97
        setRow((short)xy[0]);
93
        setRow((short)xy[0]);
98
        setColumn((short)xy[1]);
94
        setColumn((short)xy[1]);
(-)src/java/org/apache/poi/hssf/record/formula/SubtractPtg.java (-18 / +2 lines)
Lines 73-81 Link Here
73
    public final static int  SIZE = 1;
73
    public final static int  SIZE = 1;
74
    public final static byte sid  = 0x04;
74
    public final static byte sid  = 0x04;
75
75
76
    /** Creates new AddPtg */
76
    protected SubtractPtg()
77
78
    public SubtractPtg()
79
    {
77
    {
80
    }
78
    }
81
79
Lines 110-130 Link Here
110
        return "-";
108
        return "-";
111
    }
109
    }
112
110
113
    public String toFormulaString(Ptg [] operands)
111
       
114
    {
115
        StringBuffer buffer = new StringBuffer();
116
117
        buffer.append(operands[ 0 ].toFormulaString());
118
        buffer.append("-");
119
        buffer.append(operands[ 1 ].toFormulaString());
120
        return buffer.toString();
121
    }
122
123
    
124
    public int getStringLength() {
125
        return 1;
126
    }
127
    
128
    public String toFormulaString(String[] operands) {
112
    public String toFormulaString(String[] operands) {
129
        StringBuffer buffer = new StringBuffer();
113
        StringBuffer buffer = new StringBuffer();
130
114
(-)src/java/org/apache/poi/hssf/record/formula/ValueVariableFunctionPtg.java (-13 / +2 lines)
Lines 124-147 Link Here
124
        return "NO IDEA YET VALUE VARIABLE";
124
        return "NO IDEA YET VALUE VARIABLE";
125
    }
125
    }
126
126
127
    public String toFormulaString(Ptg [] operands)
127
       
128
    {
129
        return toFormulaString();
130
    }
131
132
    
133
    public String toFormulaString(String[] operands) {
128
    public String toFormulaString(String[] operands) {
134
        return toFormulaString();
129
        return toFormulaString();
135
    }
130
    }
136
    
131
    
137
   
132
   
138
    public void manipulate(List source, List results, int pos) {
133
      
139
    }
140
    
141
    public int getPrecedence() {
142
        return 1;
143
    }    
144
    
145
    
134
    
146
135
147
}
136
}
(-)src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java (-26 / +71 lines)
Lines 206-240 Link Here
206
     *
206
     *
207
     */
207
     */
208
    public void testFloat()
208
    public void testFloat()
209
        throws Exception {
209
    throws Exception {
210
            String operator = "+";
210
        floatTest("*");
211
            short            rownum = 0;
211
        floatTest("/");
212
            File file = File.createTempFile("testFormulaFloat",".xls");
212
    }
213
            FileOutputStream out    = new FileOutputStream(file);
214
            HSSFWorkbook     wb     = new HSSFWorkbook();
215
            HSSFSheet        s      = wb.createSheet();
216
            HSSFRow          r      = null;
217
            HSSFCell         c      = null;
218
219
                for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
220
                r = s.createRow((short) x);
221
222
                for (short y = 1; y < 256 && y > 0; y++) {
223
224
                    c = r.createCell((short) y);
225
                    c.setCellFormula("" + (100*x)+"."+y + operator + (10000*y) + 
226
                                     "."+x);
227
    
213
    
228
214
    private void floatTest(String operator)
229
                }
215
    throws Exception {
216
        short            rownum = 0;
217
        File file = File.createTempFile("testFormulaFloat",".xls");
218
        FileOutputStream out    = new FileOutputStream(file);
219
        HSSFWorkbook     wb     = new HSSFWorkbook();
220
        HSSFSheet        s      = wb.createSheet();
221
        HSSFRow          r      = null;
222
        HSSFCell         c      = null;
223
        
224
        //get our minimum values
225
        
226
        r = s.createRow((short)0);
227
        c = r.createCell((short)1);
228
        c.setCellFormula(""+Float.MIN_VALUE + operator + Float.MIN_VALUE);
229
 
230
       for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2) ) {
231
            r = s.createRow((short) x);
232
            
233
            for (short y = 1; y < 256 && y > 0; y= (short) (y +2)) {
234
                
235
                c = r.createCell((short) y);
236
                c.setCellFormula("" + x+"."+y + operator + y +"."+x);
237
                
238
                
239
            }
240
        }
241
        if (s.getLastRowNum() < Short.MAX_VALUE) {
242
            r = s.createRow((short)0);
243
            c = r.createCell((short)0);
244
            c.setCellFormula("" + Float.MAX_VALUE + operator + Float.MAX_VALUE);
245
        }
246
        wb.write(out);
247
        out.close();
248
        assertTrue("file exists",file.exists());
249
        out=null;wb=null;  //otherwise we get out of memory error!
250
        floatVerify(operator,file);
251
        
252
    }
253
        
254
            private void floatVerify(String operator, File file)
255
    throws Exception {
256
        short            rownum = 0;
257
        
258
        FileInputStream  in     = new FileInputStream(file);
259
        HSSFWorkbook     wb     = new HSSFWorkbook(in);
260
        HSSFSheet        s      = wb.getSheetAt(0);
261
        HSSFRow          r      = null;
262
        HSSFCell         c      = null;
263
        
264
        // dont know how to check correct result .. for the moment, we just verify that the file can be read. 
265
        
266
        for (short x = 1; x < Short.MAX_VALUE && x > 0; x=(short)(x*2)) {
267
            r = s.getRow((short) x);
268
269
            for (short y = 1; y < 256 && y > 0; y=(short)(y+2)) {
270
271
                c = r.getCell((short) y);
272
                assertTrue("got a formula",c.getCellFormula()!=null);
273
                
274
                assertTrue("loop Formula is as expected "+x+"."+y+operator+y+"."+x+"!="+c.getCellFormula(),(
275
                (""+x+"."+y+operator+y+"."+x).equals(c.getCellFormula()) ));
276
 
230
            }
277
            }
231
232
            wb.write(out);
233
            out.close();
234
            assertTrue("file exists",file.exists());
235
236
237
        }
278
        }
279
        
280
       in.close();
281
       assertTrue("file exists",file.exists());
282
    }
238
    
283
    
239
    public void testAreaSum() 
284
    public void testAreaSum() 
240
    throws Exception {
285
    throws Exception {

Return to bug 8665