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

(-)src/java/org/apache/poi/hssf/record/formula/ErrPtg.java (+90 lines)
Line 0 Link Here
1
2
/* ====================================================================
3
   Copyright 2003-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
19
package org.apache.poi.hssf.record.formula;
20
21
import org.apache.poi.hssf.model.Workbook;
22
import org.apache.poi.hssf.record.RecordInputStream;
23
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
24
25
/**
26
 * @author Daniel Noll (daniel at nuix dot com dot au)
27
 */
28
public class ErrPtg extends Ptg
29
{
30
    public static final short sid  = 0x1c;
31
    private static final int  SIZE = 7;
32
    private byte              field_1_error_code;
33
34
    /** Creates new ErrPtg */
35
36
    public ErrPtg()
37
    {
38
    }
39
40
    public ErrPtg(RecordInputStream in)
41
    {
42
        field_1_error_code = in.readByte();
43
    }
44
45
    public void writeBytes(byte [] array, int offset)
46
    {
47
        array[offset] = (byte) (sid + ptgClass);
48
        array[offset + 1] = field_1_error_code;
49
    }
50
51
    public String toFormulaString(Workbook book)
52
    {
53
        switch(field_1_error_code)
54
        {
55
            case HSSFErrorConstants.ERROR_NULL:
56
                return "#NULL!";
57
            case HSSFErrorConstants.ERROR_DIV_0:
58
                return "#DIV/0!";
59
            case HSSFErrorConstants.ERROR_VALUE:
60
                return "#VALUE!";
61
            case HSSFErrorConstants.ERROR_REF:
62
                return "#REF!";
63
            case HSSFErrorConstants.ERROR_NAME:
64
                return "#NAME?";
65
            case HSSFErrorConstants.ERROR_NUM:
66
                return "#NUM!";
67
            case HSSFErrorConstants.ERROR_NA:
68
                return "#N/A";
69
        }
70
71
        // Shouldn't happen anyway.  Excel docs say that this is returned for all other codes.
72
        return "#N/A";
73
    }
74
75
    public int getSize()
76
    {
77
        return SIZE;
78
    }
79
80
    public byte getDefaultOperandClass()
81
    {
82
        return Ptg.CLASS_VALUE;
83
    }
84
85
    public Object clone() {
86
        ErrPtg ptg = new ErrPtg();
87
        ptg.field_1_error_code = field_1_error_code;
88
        return ptg;
89
    }
90
}
0
  + *
91
  + *
(-)src/java/org/apache/poi/hssf/record/formula/RangePtg.java (+83 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Copyright 2003-2004   Apache Software Foundation
3
4
   Licensed under the Apache License, Version 2.0 (the "License");
5
   you may not use this file except in compliance with the License.
6
   You may obtain a copy of the License at
7
8
       http://www.apache.org/licenses/LICENSE-2.0
9
10
   Unless required by applicable law or agreed to in writing, software
11
   distributed under the License is distributed on an "AS IS" BASIS,
12
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
   See the License for the specific language governing permissions and
14
   limitations under the License.
15
==================================================================== */
16
17
package org.apache.poi.hssf.record.formula;
18
19
import org.apache.poi.hssf.model.Workbook;
20
import org.apache.poi.hssf.record.RecordInputStream;
21
22
/**
23
 * @author Daniel Noll (daniel at nuix dot com dot au)
24
 */
25
public class RangePtg extends OperationPtg
26
{
27
    public final static byte sid  = 0x11;
28
29
30
    public RangePtg()
31
    {
32
    }
33
34
    public RangePtg(RecordInputStream in)
35
    {
36
        // doesn't need anything
37
    }
38
39
40
    public int getSize()
41
    {
42
        return 1;
43
    }
44
45
    public void writeBytes( byte[] array, int offset )
46
    {
47
        array[ offset + 0 ] = sid;
48
    }
49
50
    public Object clone()
51
    {
52
        return new RangePtg();
53
    }
54
55
    public int getType()
56
    {
57
        return TYPE_BINARY;
58
    }
59
60
    /** Implementation of method from Ptg */
61
    public String toFormulaString(Workbook book)
62
    {
63
        return ":";
64
    }
65
66
67
    /** implementation of method from OperationsPtg*/
68
    public String toFormulaString(String[] operands)
69
    {
70
         StringBuffer buffer = new StringBuffer();
71
72
         buffer.append(operands[ 0 ]);
73
         buffer.append(":");
74
         buffer.append(operands[ 1 ]);
75
         return buffer.toString();
76
     }
77
78
    public int getNumberOfOperands()
79
    {
80
        return 2;
81
    }
82
83
}
0
  + *
84
  + *
(-)src/java/org/apache/poi/hssf/record/formula/MemAreaPtg.java (+98 lines)
Line 0 Link Here
1
2
/* ====================================================================
3
   Copyright 2003-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
19
/*
20
 * MemAreaPtg.java
21
 *
22
 * Created on November 21, 2001, 8:46 AM
23
 */
24
package org.apache.poi.hssf.record.formula;
25
26
import org.apache.poi.util.LittleEndian;
27
import org.apache.poi.hssf.model.Workbook;
28
import org.apache.poi.hssf.record.RecordInputStream;
29
30
/**
31
 * @author Daniel Noll (daniel at nuix dot com dot au)
32
 */
33
public class MemAreaPtg
34
    extends Ptg
35
{
36
    public final static short sid  = 0x26;
37
    private final static int  SIZE = 7;
38
    private int               field_1_reserved;
39
    private short             field_2_subex_len;
40
41
    /** Creates new MemAreaPtg */
42
43
    public MemAreaPtg()
44
    {
45
    }
46
47
    public MemAreaPtg(RecordInputStream in)
48
    {
49
        field_1_reserved  = in.readInt();
50
        field_2_subex_len = in.readShort();
51
    }
52
53
    public void setReserved(int res)
54
    {
55
        field_1_reserved = res;
56
    }
57
58
    public int getReserved()
59
    {
60
        return field_1_reserved;
61
    }
62
63
    public void setSubexpressionLength(short subexlen)
64
    {
65
        field_2_subex_len = subexlen;
66
    }
67
68
    public short getSubexpressionLength()
69
    {
70
        return field_2_subex_len;
71
    }
72
73
    public void writeBytes(byte [] array, int offset)
74
    {
75
        array[offset] = (byte) (sid + ptgClass);
76
        LittleEndian.putInt(array, offset + 1, field_1_reserved);
77
        LittleEndian.putShort(array, offset + 5, field_2_subex_len);
78
    }
79
80
    public int getSize()
81
    {
82
        return SIZE;
83
    }
84
85
    public String toFormulaString(Workbook book)
86
    {
87
        return ""; // TODO: Not sure how to format this. -- DN
88
    }
89
90
    public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
91
92
    public Object clone() {
93
      MemAreaPtg ptg = new MemAreaPtg();
94
      ptg.field_1_reserved = field_1_reserved;
95
      ptg.field_2_subex_len = field_2_subex_len;
96
      return ptg;
97
    }
98
}
0
  + *
99
  + *
(-)src/java/org/apache/poi/hssf/record/formula/AreaPtg.java (-1 / +1 lines)
Lines 46-52 Link Here
46
    private BitField         colRelative = BitFieldFactory.getInstance(0x4000);
46
    private BitField         colRelative = BitFieldFactory.getInstance(0x4000);
47
    private BitField         column      = BitFieldFactory.getInstance(0x3FFF);
47
    private BitField         column      = BitFieldFactory.getInstance(0x3FFF);
48
48
49
    private AreaPtg() {
49
    AreaPtg() {
50
      //Required for clone methods
50
      //Required for clone methods
51
    }
51
    }
52
   
52
   
(-)src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java (-2 / +2 lines)
Lines 359-365 Link Here
359
        dmap.put(new Integer(258),"GETTOOLBAR");
359
        dmap.put(new Integer(258),"GETTOOLBAR");
360
        dmap.put(new Integer(259),"GETTOOL");
360
        dmap.put(new Integer(259),"GETTOOL");
361
        dmap.put(new Integer(260),"SPELLINGCHECK");
361
        dmap.put(new Integer(260),"SPELLINGCHECK");
362
        dmap.put(new Integer(261),"ERRORTYPE");
362
        dmap.put(new Integer(261),"ERROR.TYPE");
363
        dmap.put(new Integer(262),"APPTITLE");
363
        dmap.put(new Integer(262),"APPTITLE");
364
        dmap.put(new Integer(263),"WINDOWTITLE");
364
        dmap.put(new Integer(263),"WINDOWTITLE");
365
        dmap.put(new Integer(264),"SAVETOOLBAR");
365
        dmap.put(new Integer(264),"SAVETOOLBAR");
Lines 716-721 Link Here
716
        
716
        
717
        
717
        
718
        
718
        
719
        functionData[261][0]=new Byte(Ptg.CLASS_VALUE);functionData[261][1]=new byte[] {Ptg.CLASS_VALUE};functionData[261][2]=new Integer(1);
719
        
720
        
720
        
721
        
721
        
722
        
Lines 723-729 Link Here
723
        
724
        
724
        
725
        
725
        
726
        
726
        
727
        functionData[269][0]=new Byte(Ptg.CLASS_VALUE);functionData[269][1]=new byte[] {Ptg.CLASS_REF};functionData[269][2]=new Integer(-1);
727
        functionData[269][0]=new Byte(Ptg.CLASS_VALUE);functionData[269][1]=new byte[] {Ptg.CLASS_REF};functionData[269][2]=new Integer(-1);
728
        functionData[270][0]=new Byte(Ptg.CLASS_VALUE);functionData[270][1]=new byte[] {Ptg.CLASS_VALUE};functionData[270][2]=new Integer(-1);
728
        functionData[270][0]=new Byte(Ptg.CLASS_VALUE);functionData[270][1]=new byte[] {Ptg.CLASS_VALUE};functionData[270][2]=new Integer(-1);
729
        functionData[271][0]=new Byte(Ptg.CLASS_VALUE);functionData[271][1]=new byte[] {Ptg.CLASS_VALUE};functionData[271][2]=new Integer(1);
729
        functionData[271][0]=new Byte(Ptg.CLASS_VALUE);functionData[271][1]=new byte[] {Ptg.CLASS_VALUE};functionData[271][2]=new Integer(1);
(-)src/java/org/apache/poi/hssf/record/formula/Ptg.java (-142 / +144 lines)
Lines 117-329 Link Here
117
        byte id     = in.readByte();
117
        byte id     = in.readByte();
118
        Ptg  retval = null;
118
        Ptg  retval = null;
119
119
120
        final byte valueRef = ReferencePtg.sid + 0x20;
121
        final byte arrayRef = ReferencePtg.sid + 0x40;
122
        final byte valueFunc = FuncPtg.sid + 0x20;
123
        final byte arrayFunc = FuncPtg.sid + 0x40;
124
        final byte valueFuncVar = FuncVarPtg.sid +0x20;
125
        final byte arrayFuncVar = FuncVarPtg.sid+0x40;
126
        final byte valueArea = AreaPtg.sid + 0x20;
127
        final byte arrayArea = AreaPtg.sid + 0x40;
128
129
        switch (id)
120
        switch (id)
130
        {
121
        {
131
            case AddPtg.sid :
122
            case ExpPtg.sid :                  // 0x01
123
                retval = new ExpPtg(in);
124
                break;
125
126
            case AddPtg.sid :                  // 0x03
132
                retval = new AddPtg(in);
127
                retval = new AddPtg(in);
133
                break;
128
                break;
134
129
135
            case SubtractPtg.sid :
130
            case SubtractPtg.sid :             // 0x04
136
                retval = new SubtractPtg(in);
131
                retval = new SubtractPtg(in);
137
                break;
132
                break;
138
133
139
            case BoolPtg.sid:
134
            case MultiplyPtg.sid :             // 0x05
140
               retval = new BoolPtg(in);
135
                retval = new MultiplyPtg(in);
141
               break;
142
143
            case IntPtg.sid :
144
                retval = new IntPtg(in);
145
                break;
136
                break;
146
137
147
            case DividePtg.sid :
138
            case DividePtg.sid :               // 0x06
148
                retval = new DividePtg(in);
139
                retval = new DividePtg(in);
149
                break;
140
                break;
150
141
151
            case MultiplyPtg.sid :
142
            case PowerPtg.sid :                // 0x07
152
                retval = new MultiplyPtg(in);
143
                retval = new PowerPtg(in);
153
                break;
144
                break;
154
145
155
            case PowerPtg.sid :
146
            case ConcatPtg.sid :               // 0x08
156
                retval = new PowerPtg(in);
147
                retval = new ConcatPtg(in);
157
                break;
148
                break;
158
 
149
159
            case EqualPtg.sid:
150
            case LessThanPtg.sid:              // 0x09
160
                retval = new EqualPtg(in);
151
                retval = new LessThanPtg(in);
161
                break;
152
                break;
162
                
153
163
            case GreaterThanPtg.sid:
154
            case LessEqualPtg.sid :            // 0x0a
164
                retval = new GreaterThanPtg(in);
155
                retval = new LessEqualPtg(in);
165
                break;
156
                break;
166
                
157
167
            case LessThanPtg.sid:
158
            case EqualPtg.sid :                // 0x0b
168
                retval = new LessThanPtg(in);
159
                retval = new EqualPtg(in);
169
                break;
160
                break;
170
161
171
			   case LessEqualPtg.sid:
162
            case GreaterEqualPtg.sid :         // 0x0c
172
			       retval = new LessEqualPtg(in);
163
                retval = new GreaterEqualPtg(in);
173
			       break;
174
			                
175
			   case GreaterEqualPtg.sid:
176
			       retval = new GreaterEqualPtg(in);
177
			       break;
178
			       
179
			   case NotEqualPtg.sid:
180
          		 retval = new NotEqualPtg(in);
181
         		 break;
182
			       
183
            case ConcatPtg.sid :
184
                retval = new ConcatPtg(in);
185
                break;
164
                break;
186
                
187
            case ArrayPtg.sid:
188
            	retval = new ArrayPtg(in);
189
            	break;
190
            case ArrayPtgV.sid:
191
            	retval = new ArrayPtgV(in);
192
            	break;            	
193
            case ArrayPtgA.sid:            	
194
            	retval = new ArrayPtgA(in);
195
            	break;
196
165
197
            case AreaPtg.sid :
166
            case GreaterThanPtg.sid :          // 0x0d
198
                retval = new AreaPtg(in);
167
                retval = new GreaterThanPtg(in);
199
                break;
168
                break;
200
            case valueArea:
169
201
                retval = new AreaPtg(in);
170
            case NotEqualPtg.sid :             // 0x0e
171
                retval = new NotEqualPtg(in);
202
                break;
172
                break;
203
            case arrayArea:
173
204
                retval = new AreaPtg(in);
174
            case IntersectionPtg.sid :         // 0x0f
175
                retval = new IntersectionPtg(in);
205
                break;
176
                break;
206
            case MemErrPtg.sid :        // 0x27       These 3 values 
177
            case UnionPtg.sid :                // 0x10
207
            case MemErrPtg.sid+0x20 :   // 0x47       documented in 
178
                retval = new UnionPtg(in);
208
            case MemErrPtg.sid+0x40 :   // 0x67       openOffice.org doc.
209
                retval = new MemErrPtg(in);
210
                break;
179
                break;
211
180
212
            case AttrPtg.sid :
181
            case RangePtg.sid :                // 0x11
213
                retval = new AttrPtg(in);
182
                retval = new RangePtg(in);
214
                break;
183
                break;
215
                
216
            case ReferencePtg.sid :
217
                retval = new ReferencePtg(in);
218
                break;   
219
            case valueRef :
220
                retval = new ReferencePtg(in);
221
                break;   
222
            case arrayRef :
223
                retval = new ReferencePtg(in);
224
                break;   
225
            case RefErrorPtg.sid:
226
                retval = new RefErrorPtg(in);
227
                break;   
228
184
229
            case ParenthesisPtg.sid :
185
            case UnaryPlusPtg.sid :            // 0x12
230
                retval = new ParenthesisPtg(in);
186
                retval = new UnaryPlusPtg(in);
231
                break;
187
                break;
232
188
233
            case MemFuncPtg.sid :
189
            case UnaryMinusPtg.sid :           // 0x13
234
                retval = new MemFuncPtg(in);
190
                retval = new UnaryMinusPtg(in);
235
                break;
191
                break;
236
192
237
            case UnionPtg.sid :
193
            case PercentPtg.sid :              // 0x14
238
                retval = new UnionPtg(in);
194
                retval = new PercentPtg(in);
239
                break;
195
                break;
240
196
241
            case FuncPtg.sid :
197
            case ParenthesisPtg.sid :          // 0x15
242
                retval = new FuncPtg(in);
198
                retval = new ParenthesisPtg(in);
243
                break;
199
                break;
244
                
200
245
            case valueFunc :
201
            case MissingArgPtg.sid :           // 0x16
246
                retval = new FuncPtg(in);
202
                retval = new MissingArgPtg(in);
247
                break;
203
                break;
248
            case arrayFunc :
204
249
                retval = new FuncPtg(in);
205
            case StringPtg.sid :               // 0x17
206
               retval = new StringPtg(in);
207
               break;
208
209
            case AttrPtg.sid :                 // 0x19
210
                retval = new AttrPtg(in);
250
                break;
211
                break;
251
212
252
            case FuncVarPtg.sid :
213
            case ErrPtg.sid :                  // 0x1c
253
                retval = new FuncVarPtg(in);
214
                retval = new ErrPtg(in);
254
                break;
215
                break;
255
                
216
256
            case valueFuncVar :
217
            case BoolPtg.sid :                 // 0x1d
257
                retval = new FuncVarPtg(in);
218
               retval = new BoolPtg(in);
219
               break;
220
221
            case IntPtg.sid :                  // 0x1e
222
                retval = new IntPtg(in);
258
                break;
223
                break;
259
            case arrayFuncVar :
224
260
                retval = new FuncVarPtg(in);
225
            case NumberPtg.sid :               // 0x1f
261
                break;
262
                
263
            case NumberPtg.sid :
264
               retval = new NumberPtg(in);
226
               retval = new NumberPtg(in);
265
               break;
227
               break;
266
228
267
            case StringPtg.sid :
229
            case ArrayPtg.sid :                // 0x20
268
               retval = new StringPtg(in);
230
            	retval = new ArrayPtg(in);
269
               break;
231
            	break;
232
            case ArrayPtgV.sid :               // 0x40
233
            	retval = new ArrayPtgV(in);
234
            	break;
235
            case ArrayPtgA.sid :               // 0x60
236
            	retval = new ArrayPtgA(in);
237
            	break;
270
238
271
            case NamePtg.sid :            // 0x23     These 3 values
239
            case FuncPtg.sid :                 // 0x21
272
            case NamePtg.sid+0x20 :       // 0x43     documented in
240
            case FuncPtg.sid + 0x20 :          // 0x41
273
            case NamePtg.sid+0x40 :       // 0x63     openOffice.org doc.
241
            case FuncPtg.sid + 0x40 :          // 0x61
242
                retval = new FuncPtg(in);
243
                break;
274
244
275
                retval = new NamePtg(in);
245
            case FuncVarPtg.sid :              // 0x22
246
            case FuncVarPtg.sid + 0x20 :       // 0x42
247
            case FuncVarPtg.sid + 0x40 :       // 0x62
248
                retval = new FuncVarPtg(in);
276
                break;
249
                break;
277
                
278
            case NameXPtg.sid :            // 0x39
279
            case NameXPtg.sid+0x20 :       // 0x45
280
            case NameXPtg.sid+0x40 :       // 0x79
281
250
282
                retval = new NameXPtg(in);
251
            case ReferencePtg.sid :            // 0x24
252
            case ReferencePtg.sid + 0x20 :     // 0x44
253
            case ReferencePtg.sid + 0x40 :     // 0x64
254
                retval = new ReferencePtg(in);
283
                break;
255
                break;
284
256
285
            case ExpPtg.sid :
257
            case AreaPtg.sid :                 // 0x25
286
                retval = new ExpPtg(in);
258
            case AreaPtg.sid + 0x20 :          // 0x45
259
            case AreaPtg.sid + 0x40 :          // 0x65
260
                retval = new AreaPtg(in);
287
                break;
261
                break;
288
262
289
            case Area3DPtg.sid :          // 0x3b     These 3 values 
263
            case MemAreaPtg.sid :              // 0x26
290
             case Area3DPtg.sid+0x20 :     // 0x5b     documented in 
264
            case MemAreaPtg.sid + 0x40 :       // 0x46
291
             case Area3DPtg.sid+0x40 :     // 0x7b     openOffice.org doc.
265
            case MemAreaPtg.sid + 0x20 :       // 0x66
266
                retval = new MemAreaPtg(in);
267
                break;
292
268
293
                retval = new Area3DPtg(in);
269
            case MemErrPtg.sid :               // 0x27
270
            case MemErrPtg.sid + 0x20 :        // 0x47
271
            case MemErrPtg.sid + 0x40 :        // 0x67
272
                retval = new MemErrPtg(in);
294
                break;
273
                break;
295
274
296
            case Ref3DPtg.sid:            // 0x3a     These 3 values 
275
            case MemFuncPtg.sid :              // 0x29
297
             case Ref3DPtg.sid+0x20:       // 0x5a     documented in 
276
                retval = new MemFuncPtg(in);
298
             case Ref3DPtg.sid+0x40:       // 0x7a     openOffice.org doc.
277
                break;
299
278
300
                retval = new Ref3DPtg(in);
279
            case RefErrorPtg.sid :             // 0x2a
280
            case RefErrorPtg.sid + 0x20 :      // 0x4a
281
            case RefErrorPtg.sid + 0x40 :      // 0x6a
282
                retval = new RefErrorPtg(in);
301
                break;
283
                break;
302
                
303
            case DeletedArea3DPtg.sid :      // 0x3d     
304
            case DeletedArea3DPtg.sid+0x20 : // 0x5d     
305
            case DeletedArea3DPtg.sid+0x40 : // 0x7d     
306
284
307
                retval = new DeletedArea3DPtg(in);
285
            case AreaErrPtg.sid :              // 0x2b
286
            case AreaErrPtg.sid + 0x20 :       // 0x4b
287
            case AreaErrPtg.sid + 0x40 :       // 0x6b
288
                retval = new AreaErrPtg(in);
308
                break;
289
                break;
309
290
310
            case DeletedRef3DPtg.sid:      // 0x3c      
291
            case NamePtg.sid :                 // 0x23
311
            case DeletedRef3DPtg.sid+0x20: // 0x5c     
292
            case NamePtg.sid + 0x20 :          // 0x43
312
            case DeletedRef3DPtg.sid+0x40: // 0x7c     
293
            case NamePtg.sid + 0x40 :          // 0x63
294
                retval = new NamePtg(in);
295
                break;
313
296
314
                retval = new DeletedRef3DPtg(in);
297
            case NameXPtg.sid :                // 0x39
298
            case NameXPtg.sid + 0x20 :         // 0x45
299
            case NameXPtg.sid + 0x40 :         // 0x79
300
                retval = new NameXPtg(in);
315
                break;
301
                break;
316
                
302
317
            case MissingArgPtg.sid:
303
            case Area3DPtg.sid :               // 0x3b
318
                retval = new MissingArgPtg(in);
304
            case Area3DPtg.sid + 0x20 :        // 0x5b
305
            case Area3DPtg.sid + 0x40 :        // 0x7b
306
                retval = new Area3DPtg(in);
319
                break;
307
                break;
320
            case UnaryPlusPtg.sid:
308
321
                retval=new UnaryPlusPtg(in);
309
            case Ref3DPtg.sid :                // 0x3a
310
            case Ref3DPtg.sid + 0x20:          // 0x5a
311
            case Ref3DPtg.sid + 0x40:          // 0x7a
312
                retval = new Ref3DPtg(in);
322
                break;
313
                break;
323
            case UnaryMinusPtg.sid:
314
324
                retval=new UnaryMinusPtg(in);
315
            case DeletedRef3DPtg.sid:          // 0x3c
316
            case DeletedRef3DPtg.sid + 0x20:   // 0x5c
317
            case DeletedRef3DPtg.sid + 0x40:   // 0x7c
318
                retval = new DeletedRef3DPtg(in);
325
                break;
319
                break;
326
320
321
            case DeletedArea3DPtg.sid :        // 0x3d
322
            case DeletedArea3DPtg.sid + 0x20 : // 0x5d
323
            case DeletedArea3DPtg.sid + 0x40 : // 0x7d
324
                retval = new DeletedArea3DPtg(in);
325
                break;
326
327
            default :
327
            default :
328
328
329
                 //retval = new UnknownPtg();
329
                 //retval = new UnknownPtg();
Lines 335-342 Link Here
335
            retval.setClass(CLASS_ARRAY);
335
            retval.setClass(CLASS_ARRAY);
336
        } else if (id > 0x40) {
336
        } else if (id > 0x40) {
337
            retval.setClass(CLASS_VALUE);
337
            retval.setClass(CLASS_VALUE);
338
        } else 
338
        } else {
339
            retval.setClass(CLASS_REF);
339
            retval.setClass(CLASS_REF);
340
        }
341
340
       return retval;
342
       return retval;
341
        
343
        
342
    }
344
    }
(-)src/java/org/apache/poi/hssf/record/formula/AreaErrPtg.java (+88 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Copyright 2003-2004   Apache Software Foundation
3
4
   Licensed under the Apache License, Version 2.0 (the "License");
5
   you may not use this file except in compliance with the License.
6
   You may obtain a copy of the License at
7
8
       http://www.apache.org/licenses/LICENSE-2.0
9
10
   Unless required by applicable law or agreed to in writing, software
11
   distributed under the License is distributed on an "AS IS" BASIS,
12
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
   See the License for the specific language governing permissions and
14
   limitations under the License.
15
==================================================================== */
16
17
package org.apache.poi.hssf.record.formula;
18
19
import org.apache.poi.util.LittleEndian;
20
import org.apache.poi.util.BitField;
21
22
import org.apache.poi.hssf.model.Workbook;
23
import org.apache.poi.hssf.record.RecordInputStream;
24
25
/**
26
 * AreaErr - handles deleted cell area references.
27
 *
28
 * @author Daniel Noll (daniel at nuix dot com dot au)
29
 */
30
public class AreaErrPtg extends AreaPtg
31
{
32
    public final static byte sid  = 0x2b;
33
34
    private AreaErrPtg()
35
    {
36
        //Required for clone methods
37
        super();
38
    }
39
    
40
    public AreaErrPtg(RecordInputStream in)
41
    {
42
        super(in);
43
    }
44
45
    public String toString()
46
    {
47
        StringBuffer buffer = new StringBuffer();
48
49
        buffer.append("AreaErrPtg\n");
50
        buffer.append("firstRow = " + getFirstRow()).append("\n");
51
        buffer.append("lastRow  = " + getLastRow()).append("\n");
52
        buffer.append("firstCol = " + getFirstColumn()).append("\n");
53
        buffer.append("lastCol  = " + getLastColumn()).append("\n");
54
        buffer.append("firstColRowRel= "
55
                      + isFirstRowRelative()).append("\n");
56
        buffer.append("lastColRowRel = "
57
                      + isLastRowRelative()).append("\n");
58
        buffer.append("firstColRel   = " + isFirstColRelative()).append("\n");
59
        buffer.append("lastColRel    = " + isLastColRelative()).append("\n");
60
        return buffer.toString();
61
    }
62
63
    public void writeBytes(byte [] array, int offset) {
64
        super.writeBytes(array, offset);
65
        array[offset] = (byte) (sid + ptgClass);
66
    }
67
68
    public String toFormulaString(Workbook book)
69
    {
70
        return "#REF!";
71
    }
72
    
73
    public Object clone()
74
    {
75
        AreaErrPtg ptg = new AreaErrPtg();
76
        ptg.setFirstRow(getFirstRow());
77
        ptg.setFirstColumn(getFirstColumn());
78
        ptg.setLastRow(getLastRow());
79
        ptg.setLastColumn(getLastColumn());
80
        ptg.setFirstColRelative(isFirstColRelative());
81
        ptg.setLastColRelative(isLastColRelative());
82
        ptg.setFirstRowRelative(isFirstRowRelative());
83
        ptg.setLastRowRelative(isLastRowRelative());
84
        ptg.setClass(ptgClass);
85
        return ptg;
86
    }
87
}
88
0
  + *
89
  + *
(-)src/java/org/apache/poi/hssf/record/formula/MemErrPtg.java (-34 / +7 lines)
Lines 31-45 Link Here
31
 *
31
 *
32
 * @author  andy
32
 * @author  andy
33
 * @author Jason Height (jheight at chariot dot net dot au)
33
 * @author Jason Height (jheight at chariot dot net dot au)
34
 * @author Daniel Noll (daniel at nuix dot com dot au)
34
 */
35
 */
35
36
36
public class MemErrPtg
37
public class MemErrPtg
37
    extends Ptg
38
    extends MemAreaPtg
38
{
39
{
39
    public final static short sid  = 0x27;
40
    public final static short sid  = 0x27;
40
    private final static int  SIZE = 7;
41
    private int               field_1_reserved;
42
    private short             field_2_subex_len;
43
41
44
    /** Creates new MemErrPtg */
42
    /** Creates new MemErrPtg */
45
43
Lines 49-97 Link Here
49
47
50
    public MemErrPtg(RecordInputStream in)
48
    public MemErrPtg(RecordInputStream in)
51
    {
49
    {
52
        field_1_reserved  = in.readInt();
50
        super(in);
53
        field_2_subex_len = in.readShort();
54
    }
51
    }
55
52
56
    public void setReserved(int res)
57
    {
58
        field_1_reserved = res;
59
    }
60
61
    public int getReserved()
62
    {
63
        return field_1_reserved;
64
    }
65
66
    public void setSubexpressionLength(short subexlen)
67
    {
68
        field_2_subex_len = subexlen;
69
    }
70
71
    public short getSubexpressionLength()
72
    {
73
        return field_2_subex_len;
74
    }
75
76
    public void writeBytes(byte [] array, int offset)
53
    public void writeBytes(byte [] array, int offset)
77
    {
54
    {
55
        super.writeBytes(array, offset);
56
        array[offset] = (byte) (sid + ptgClass);
78
    }
57
    }
79
58
80
    public int getSize()
81
    {
82
        return SIZE;
83
    }
84
85
    public String toFormulaString(Workbook book)
59
    public String toFormulaString(Workbook book)
86
    {
60
    {
87
        return "ERR#";
61
        return "ERR#";
88
    }
62
    }
89
    public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
90
63
91
    public Object clone() {
64
    public Object clone() {
92
      MemErrPtg ptg = new MemErrPtg();
65
      MemErrPtg ptg = new MemErrPtg();
93
      ptg.field_1_reserved = field_1_reserved;
66
      ptg.setReserved(getReserved());
94
      ptg.field_2_subex_len = field_2_subex_len;
67
      ptg.setSubexpressionLength(getSubexpressionLength());
95
      return ptg;
68
      return ptg;
96
    }
69
    }
97
}
70
}
(-)src/java/org/apache/poi/hssf/record/formula/PercentPtg.java (+96 lines)
Line 0 Link Here
1
2
/* ====================================================================
3
   Copyright 2003-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
/*
19
 * PercentPtg.java
20
 *
21
 * Created on March 29, 2006, 9:23 PM
22
 */
23
package org.apache.poi.hssf.record.formula;
24
25
import org.apache.poi.hssf.model.Workbook;
26
import org.apache.poi.hssf.record.RecordInputStream;
27
28
/**
29
 * Percent PTG.
30
 *
31
 * @author Daniel Noll (daniel at nuix.com.au)
32
 */
33
34
public class PercentPtg
35
    extends OperationPtg
36
{
37
    public final static int  SIZE = 1;
38
    public final static byte sid  = 0x14;
39
    
40
    private final static String PERCENT = "%";
41
42
    /** Creates new PercentPtg */
43
44
    public PercentPtg()
45
    {
46
    }
47
48
    public PercentPtg(RecordInputStream in)
49
    {
50
51
        // doesn't need anything
52
    }
53
    
54
   
55
    public void writeBytes(byte [] array, int offset)
56
    {
57
        array[ offset + 0 ] = sid;
58
    }
59
60
    public int getSize()
61
    {
62
        return SIZE;
63
    }
64
65
    public int getType()
66
    {
67
        return TYPE_UNARY;
68
    }
69
70
    public int getNumberOfOperands()
71
    {
72
        return 1;
73
    }
74
    
75
    /** Implementation of method from Ptg */
76
    public String toFormulaString(Workbook book)
77
    {
78
        return "%";
79
    }
80
       
81
   /** implementation of method from OperationsPtg*/  
82
    public String toFormulaString(String[] operands) {
83
        StringBuffer buffer = new StringBuffer();
84
85
        buffer.append(operands[ 0 ]);
86
        buffer.append(PERCENT);
87
        return buffer.toString();
88
    }
89
    
90
    public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
91
           
92
    public Object clone() {
93
      return new PercentPtg();
94
    }
95
96
}
(-)src/java/org/apache/poi/hssf/record/formula/IntersectionPtg.java (+83 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Copyright 2003-2004   Apache Software Foundation
3
4
   Licensed under the Apache License, Version 2.0 (the "License");
5
   you may not use this file except in compliance with the License.
6
   You may obtain a copy of the License at
7
8
       http://www.apache.org/licenses/LICENSE-2.0
9
10
   Unless required by applicable law or agreed to in writing, software
11
   distributed under the License is distributed on an "AS IS" BASIS,
12
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
   See the License for the specific language governing permissions and
14
   limitations under the License.
15
==================================================================== */
16
17
package org.apache.poi.hssf.record.formula;
18
19
import org.apache.poi.hssf.model.Workbook;
20
import org.apache.poi.hssf.record.RecordInputStream;
21
22
/**
23
 * @author Daniel Noll (daniel at nuix dot com dot au)
24
 */
25
public class IntersectionPtg extends OperationPtg
26
{
27
    public final static byte sid  = 0x0f;
28
29
30
    public IntersectionPtg()
31
    {
32
    }
33
34
    public IntersectionPtg(RecordInputStream in)
35
    {
36
        // doesn't need anything
37
    }
38
39
40
    public int getSize()
41
    {
42
        return 1;
43
    }
44
45
    public void writeBytes( byte[] array, int offset )
46
    {
47
        array[ offset + 0 ] = sid;
48
    }
49
50
    public Object clone()
51
    {
52
        return new IntersectionPtg();
53
    }
54
55
    public int getType()
56
    {
57
        return TYPE_BINARY;
58
    }
59
60
    /** Implementation of method from Ptg */
61
    public String toFormulaString(Workbook book)
62
    {
63
        return " ";
64
    }
65
66
67
    /** implementation of method from OperationsPtg*/
68
    public String toFormulaString(String[] operands)
69
    {
70
         StringBuffer buffer = new StringBuffer();
71
72
         buffer.append(operands[ 0 ]);
73
         buffer.append(" ");
74
         buffer.append(operands[ 1 ]);
75
         return buffer.toString();
76
     }
77
78
    public int getNumberOfOperands()
79
    {
80
        return 2;
81
    }
82
83
}
0
  + *
84
  + *
(-)src/testcases/org/apache/poi/hssf/HSSFTests.java (+12 lines)
Lines 74-80 Link Here
74
import org.apache.poi.hssf.record.TestValueRangeRecord;
74
import org.apache.poi.hssf.record.TestValueRangeRecord;
75
import org.apache.poi.hssf.record.aggregates.TestRowRecordsAggregate;
75
import org.apache.poi.hssf.record.aggregates.TestRowRecordsAggregate;
76
import org.apache.poi.hssf.record.aggregates.TestValueRecordsAggregate;
76
import org.apache.poi.hssf.record.aggregates.TestValueRecordsAggregate;
77
import org.apache.poi.hssf.record.formula.TestAreaErrPtg;
78
import org.apache.poi.hssf.record.formula.TestErrPtg;
77
import org.apache.poi.hssf.record.formula.TestFuncPtg;
79
import org.apache.poi.hssf.record.formula.TestFuncPtg;
80
import org.apache.poi.hssf.record.formula.TestIntersectionPtg;
81
import org.apache.poi.hssf.record.formula.TestPercentPtg;
82
import org.apache.poi.hssf.record.formula.TestRangePtg;
83
import org.apache.poi.hssf.record.formula.TestUnionPtg;
78
import org.apache.poi.hssf.usermodel.TestBugs;
84
import org.apache.poi.hssf.usermodel.TestBugs;
79
import org.apache.poi.hssf.usermodel.TestCellStyle;
85
import org.apache.poi.hssf.usermodel.TestCellStyle;
80
import org.apache.poi.hssf.usermodel.TestCloneSheet;
86
import org.apache.poi.hssf.usermodel.TestCloneSheet;
Lines 207-213 Link Here
207
        suite.addTest(new TestSuite(TestSheetReferences.class));
213
        suite.addTest(new TestSuite(TestSheetReferences.class));
208
        
214
        
209
        
215
        
216
        suite.addTest(new TestSuite(TestAreaErrPtg.class));
217
        suite.addTest(new TestSuite(TestErrPtg.class));
210
        suite.addTest(new TestSuite(TestFuncPtg.class));
218
        suite.addTest(new TestSuite(TestFuncPtg.class));
219
        suite.addTest(new TestSuite(TestIntersectionPtg.class));
220
        suite.addTest(new TestSuite(TestPercentPtg.class));
221
        suite.addTest(new TestSuite(TestRangePtg.class));
222
        suite.addTest(new TestSuite(TestUnionPtg.class));
211
		  suite.addTest(new TestSuite(TestValueRecordsAggregate.class));
223
		  suite.addTest(new TestSuite(TestValueRecordsAggregate.class));
212
		  suite.addTest(new TestSuite(TestNameRecord.class));
224
		  suite.addTest(new TestSuite(TestNameRecord.class));
213
                  suite.addTest(new TestSuite(TestEventRecordFactory.class));
225
                  suite.addTest(new TestSuite(TestEventRecordFactory.class));
(-)src/testcases/org/apache/poi/hssf/record/formula/TestIntersectionPtg.java (+42 lines)
Line 0 Link Here
1
        
2
/* ====================================================================
3
   Copyright 2003-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hssf.record.formula;
19
20
import org.apache.poi.hssf.usermodel.HSSFCell;
21
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
22
23
/**
24
 * Tests for {@link IntersectionPtg}.
25
 *
26
 * @author Daniel Noll (daniel at nuix dot com dot au)
27
 */
28
public class TestIntersectionPtg extends AbstractPtgTestCase
29
{
30
    /**
31
     * Tests reading a file containing this ptg.
32
     */
33
    public void testReading() throws Exception
34
    {
35
        HSSFWorkbook workbook = loadWorkbook("IntersectionPtg.xls");
36
        HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell((short) 2);
37
        assertEquals("Wrong cell value", 5.0, cell.getNumericCellValue(), 0.0);
38
        assertEquals("Wrong cell formula", "SUM(A1:B2 B2:C3)", cell.getCellFormula());
39
    }
40
}
41
42
0
  + *
43
  + *
(-)src/testcases/org/apache/poi/hssf/record/formula/TestErrPtg.java (+42 lines)
Line 0 Link Here
1
        
2
/* ====================================================================
3
   Copyright 2003-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hssf.record.formula;
19
20
import org.apache.poi.hssf.usermodel.HSSFCell;
21
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
22
23
/**
24
 * Tests for {@link ErrPtg}.
25
 *
26
 * @author Daniel Noll (daniel at nuix dot com dot au)
27
 */
28
public class TestErrPtg extends AbstractPtgTestCase
29
{
30
    /**
31
     * Tests reading a file containing this ptg.
32
     */
33
    public void testReading() throws Exception
34
    {
35
        HSSFWorkbook workbook = loadWorkbook("ErrPtg.xls");
36
        HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell((short) 0);
37
        assertEquals("Wrong cell value", 4.0, cell.getNumericCellValue(), 0.0);
38
        assertEquals("Wrong cell formula", "ERROR.TYPE(#REF!)", cell.getCellFormula());
39
    }
40
}
41
42
0
  + *
43
  + *
(-)src/testcases/org/apache/poi/hssf/record/formula/TestUnionPtg.java (+42 lines)
Line 0 Link Here
1
        
2
/* ====================================================================
3
   Copyright 2003-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hssf.record.formula;
19
20
import org.apache.poi.hssf.usermodel.HSSFCell;
21
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
22
23
/**
24
 * Tests for {@link UnionPtg}.
25
 *
26
 * @author Daniel Noll (daniel at nuix dot com dot au)
27
 */
28
public class TestUnionPtg extends AbstractPtgTestCase
29
{
30
    /**
31
     * Tests reading a file containing this ptg.
32
     */
33
    public void testReading() throws Exception
34
    {
35
        HSSFWorkbook workbook = loadWorkbook("UnionPtg.xls");
36
        HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell((short) 2);
37
        assertEquals("Wrong cell value", 24.0, cell.getNumericCellValue(), 0.0);
38
        assertEquals("Wrong cell formula", "SUM(A1:B2,B2:C3)", cell.getCellFormula());
39
    }
40
}
41
42
0
  + *
43
  + *
(-)src/testcases/org/apache/poi/hssf/record/formula/TestRangePtg.java (+42 lines)
Line 0 Link Here
1
        
2
/* ====================================================================
3
   Copyright 2003-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hssf.record.formula;
19
20
import org.apache.poi.hssf.usermodel.HSSFCell;
21
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
22
23
/**
24
 * Tests for {@link RangePtg}.
25
 *
26
 * @author Daniel Noll (daniel at nuix dot com dot au)
27
 */
28
public class TestRangePtg extends AbstractPtgTestCase
29
{
30
    /**
31
     * Tests reading a file containing this ptg.
32
     */
33
    public void testReading() throws Exception
34
    {
35
        HSSFWorkbook workbook = loadWorkbook("RangePtg.xls");
36
        HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell((short) 1);
37
        assertEquals("Wrong cell value", 10.0, cell.getNumericCellValue(), 0.0);
38
        assertEquals("Wrong cell formula", "SUM(pineapple:B2)", cell.getCellFormula());
39
    }
40
}
41
42
0
  + *
43
  + *
(-)src/testcases/org/apache/poi/hssf/record/formula/AbstractPtgTestCase.java (+61 lines)
Line 0 Link Here
1
        
2
/* ====================================================================
3
   Copyright 2003-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hssf.record.formula;
19
20
import java.io.BufferedInputStream;
21
import java.io.File;
22
import java.io.FileInputStream;
23
import java.io.IOException;
24
import java.io.InputStream;
25
26
import junit.framework.TestCase;
27
28
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
29
30
/**
31
 * Convenient abstract class to reduce the amount of boilerplate code needed
32
 * in ptg-related unit tests.
33
 *
34
 * @author Daniel Noll (daniel at nuix dot com dot au)
35
 */
36
public class AbstractPtgTestCase extends TestCase
37
{
38
    /** Directory containing the test data. */
39
    private static String dataDir = System.getProperty("HSSF.testdata.path");
40
41
    /**
42
     * Loads a workbook from the given filename in the test data dir.
43
     *
44
     * @param filename the filename.
45
     * @return the loaded workbook.
46
     * @throws IOException if an error occurs loading the workbook.
47
     */
48
    protected static HSSFWorkbook loadWorkbook(String filename)
49
            throws IOException {
50
        File file = new File(dataDir, filename);
51
        InputStream stream = new BufferedInputStream(new FileInputStream(file));
52
        try
53
        {
54
            return new HSSFWorkbook(stream);
55
        }
56
        finally
57
        {
58
            stream.close();
59
        }
60
    }
61
}
0
  + *
62
  + *
(-)src/testcases/org/apache/poi/hssf/record/formula/TestPercentPtg.java (+47 lines)
Line 0 Link Here
1
        
2
/* ====================================================================
3
   Copyright 2003-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hssf.record.formula;
19
20
import org.apache.poi.hssf.usermodel.HSSFSheet;
21
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
22
23
/**
24
 * Tests for {@link PercentPtg}.
25
 *
26
 * @author Daniel Noll (daniel at nuix dot com dot au)
27
 */
28
public class TestPercentPtg extends AbstractPtgTestCase
29
{
30
    /**
31
     * Tests reading a file containing this ptg.
32
     */
33
    public void testReading() throws Exception
34
    {
35
        HSSFWorkbook workbook = loadWorkbook("PercentPtg.xls");
36
        HSSFSheet sheet = workbook.getSheetAt(0);
37
38
        assertEquals("Wrong numeric value for original number", 53000.0,
39
                     sheet.getRow(0).getCell((short) 0).getNumericCellValue(), 0.0);
40
        assertEquals("Wrong numeric value for percent formula result", 5300.0,
41
                     sheet.getRow(1).getCell((short) 0).getNumericCellValue(), 0.0);
42
        assertEquals("Wrong formula string for percent formula", "A1*10%",
43
                     sheet.getRow(1).getCell((short) 0).getCellFormula());
44
    }
45
}
46
47
0
  + *
48
  + *
(-)src/testcases/org/apache/poi/hssf/record/formula/TestAreaErrPtg.java (+40 lines)
Line 0 Link Here
1
        
2
/* ====================================================================
3
   Copyright 2003-2004   Apache Software Foundation
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.hssf.record.formula;
19
20
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
21
22
/**
23
 * Tests for {@link AreaErrPtg}.
24
 *
25
 * @author Daniel Noll (daniel at nuix dot com dot au)
26
 */
27
public class TestAreaErrPtg extends AbstractPtgTestCase
28
{
29
    /**
30
     * Tests reading a file containing this ptg.
31
     */
32
    public void testReading() throws Exception
33
    {
34
        HSSFWorkbook workbook = loadWorkbook("AreaErrPtg.xls");
35
        assertEquals("Wrong formula string for area error", "SUM(#REF!)",
36
                     workbook.getSheetAt(0).getRow(0).getCell((short) 2).getCellFormula());
37
    }
38
}
39
40
0
  + *
41
  + *

Return to bug 40024