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

(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java (-1 / +1 lines)
Lines 304-310 Link Here
304
     * @return HSSFCell representing that column or null if undefined.
304
     * @return HSSFCell representing that column or null if undefined.
305
     */
305
     */
306
306
307
    public HSSFCell getCell(short cellnum)
307
    public HSSFCell getCell(int cellnum)
308
    {
308
    {
309
      if(cellnum<0||cellnum>=cells.length) return null;
309
      if(cellnum<0||cellnum>=cells.length) return null;
310
      return cells[cellnum];
310
      return cells[cellnum];
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/util/CellReference.java (+8 lines)
Lines 71-76 Link Here
71
        this(null, pRow, pCol, pAbsRow, pAbsCol);
71
        this(null, pRow, pCol, pAbsRow, pAbsCol);
72
    }
72
    }
73
    public CellReference(String pSheetName, int pRow, int pCol, boolean pAbsRow, boolean pAbsCol) {
73
    public CellReference(String pSheetName, int pRow, int pCol, boolean pAbsRow, boolean pAbsCol) {
74
        // TODO - "-1" is a special value being temporarily used for whole row and whole column area references.
75
        // so these checks are currently N.Q.R.
76
        if(pRow < -1) {
77
            throw new IllegalArgumentException("row index may not be negative");
78
        }
79
        if(pCol < -1) {
80
            throw new IllegalArgumentException("column index may not be negative");
81
        }
74
        _sheetName = pSheetName;
82
        _sheetName = pSheetName;
75
        _rowIndex=pRow;
83
        _rowIndex=pRow;
76
        _colIndex=pCol;
84
        _colIndex=pCol;
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java (-44 / +40 lines)
Lines 1-4 Link Here
1
2
/* ====================================================================
1
/* ====================================================================
3
   Licensed to the Apache Software Foundation (ASF) under one or more
2
   Licensed to the Apache Software Foundation (ASF) under one or more
4
   contributor license agreements.  See the NOTICE file distributed with
3
   contributor license agreements.  See the NOTICE file distributed with
Lines 15-22 Link Here
15
   See the License for the specific language governing permissions and
14
   See the License for the specific language governing permissions and
16
   limitations under the License.
15
   limitations under the License.
17
==================================================================== */
16
==================================================================== */
18
        
17
 
19
20
package org.apache.poi.hssf.record;
18
package org.apache.poi.hssf.record;
21
19
22
import java.util.Stack;
20
import java.util.Stack;
Lines 34-43 Link Here
34
 * record types.
32
 * record types.
35
 * @author Danny Mui at apache dot org
33
 * @author Danny Mui at apache dot org
36
 */
34
 */
37
35
public final class SharedFormulaRecord extends Record {
38
public class SharedFormulaRecord
39
    extends Record
40
{
41
	 public final static short   sid = 0x4BC;
36
	 public final static short   sid = 0x4BC;
42
    
37
    
43
    private int               field_1_first_row;
38
    private int               field_1_first_row;
Lines 58-72 Link Here
58
53
59
    public SharedFormulaRecord(RecordInputStream in)
54
    public SharedFormulaRecord(RecordInputStream in)
60
    {
55
    {
61
    	  super(in);
56
          super(in);
62
    }
57
    }
63
    
58
    
64
    protected void validateSid(short id)
59
    protected void validateSid(short id)
65
    {
60
    {
66
		if (id != this.sid)
61
        if (id != this.sid)
67
		{
62
        {
68
			throw new RecordFormatException("Not a valid SharedFormula");
63
            throw new RecordFormatException("Not a valid SharedFormula");
69
		}        
64
        }        
70
    }    
65
    }    
71
    
66
    
72
    public int getFirstRow() {
67
    public int getFirstRow() {
Lines 96-109 Link Here
96
91
97
    public int serialize(int offset, byte [] data)
92
    public int serialize(int offset, byte [] data)
98
    {
93
    {
99
    	//Because this record is converted to individual Formula records, this method is not required.
94
        //Because this record is converted to individual Formula records, this method is not required.
100
    	throw new UnsupportedOperationException("Cannot serialize a SharedFormulaRecord");
95
        throw new UnsupportedOperationException("Cannot serialize a SharedFormulaRecord");
101
    }
96
    }
102
97
103
    public int getRecordSize()
98
    public int getRecordSize()
104
    {
99
    {
105
    	//Because this record is converted to individual Formula records, this method is not required.
100
        //Because this record is converted to individual Formula records, this method is not required.
106
    	throw new UnsupportedOperationException("Cannot get the size for a SharedFormulaRecord");
101
        throw new UnsupportedOperationException("Cannot get the size for a SharedFormulaRecord");
107
102
108
    }
103
    }
109
104
Lines 257-295 Link Here
257
      }
252
      }
258
    }
253
    }
259
    
254
    
260
    private short fixupRelativeColumn(int currentcolumn, short column, boolean relative) {
255
    private int fixupRelativeColumn(int currentcolumn, int column, boolean relative) {
261
    	if(relative) {
256
        if(relative) {
262
    		if((column&128)!=0) column=(short)(column-256);
257
            // mask out upper bits to produce 'wrapping' at column 256 ("IV")
263
    		column+=currentcolumn;
258
            return (column + currentcolumn) & 0x00FF;
264
    	}
259
        }
265
    	return column;
260
        return column;
266
	}
261
    }
267
262
268
	private short fixupRelativeRow(int currentrow, short row, boolean relative) {
263
    private int fixupRelativeRow(int currentrow, int row, boolean relative) {
269
		if(relative) {
264
        if(relative) {
270
			row+=currentrow;
265
            // mask out upper bits to produce 'wrapping' at row 65536
271
		}
266
            return (row+currentrow) & 0x00FFFF;
272
		return row;
267
        }
273
	}
268
        return row;
269
    }
274
270
275
	/**
271
    /**
276
	 * Mirroring formula records so it is registered in the ValueRecordsAggregate
272
     * Mirroring formula records so it is registered in the ValueRecordsAggregate
277
	 */
273
     */
278
	public boolean isInValueSection()
274
    public boolean isInValueSection()
279
	{
275
    {
280
		 return true;
276
         return true;
281
	}
277
    }
282
278
283
279
284
	 /**
280
     /**
285
	  * Register it in the ValueRecordsAggregate so it can go into the FormulaRecordAggregate
281
      * Register it in the ValueRecordsAggregate so it can go into the FormulaRecordAggregate
286
	  */
282
      */
287
	 public boolean isValue() {
283
     public boolean isValue() {
288
	 	return true;
284
         return true;
289
	 }
285
     }
290
286
291
    public Object clone() {
287
    public Object clone() {
292
    	//Because this record is converted to individual Formula records, this method is not required.
288
        //Because this record is converted to individual Formula records, this method is not required.
293
    	throw new UnsupportedOperationException("Cannot clone a SharedFormulaRecord");
289
        throw new UnsupportedOperationException("Cannot clone a SharedFormulaRecord");
294
    }
290
    }
295
}
291
}
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/record/formula/AreaVPtg.java (-2 / +2 lines)
Lines 36-42 Link Here
36
 * @author Jason Height (jheight at chariot dot net dot au)
36
 * @author Jason Height (jheight at chariot dot net dot au)
37
 */
37
 */
38
38
39
public class AreaVPtg
39
public final class AreaVPtg
40
    extends AreaPtg
40
    extends AreaPtg
41
{
41
{
42
    public final static short sid  = 0x45;
42
    public final static short sid  = 0x45;
Lines 45-51 Link Here
45
      //Required for clone methods
45
      //Required for clone methods
46
    }
46
    }
47
47
48
    public AreaVPtg(short firstRow, short lastRow, short firstColumn, short lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
48
    public AreaVPtg(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
49
      super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
49
      super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
50
    }
50
    }
51
51
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java (-42 / +63 lines)
Lines 38-47 Link Here
38
{
38
{
39
    public final static short sid  = 0x25;
39
    public final static short sid  = 0x25;
40
    private final static int  SIZE = 9;
40
    private final static int  SIZE = 9;
41
    private short             field_1_first_row;
41
    /** zero based, unsigned 16 bit */
42
    private short             field_2_last_row;
42
    private int             field_1_first_row;
43
    private short             field_3_first_column;
43
    /** zero based, unsigned 16 bit */
44
    private short             field_4_last_column;
44
    private int             field_2_last_row;
45
    /** zero based, unsigned 8 bit */
46
    private int             field_3_first_column;
47
    /** zero based, unsigned 8 bit */
48
    private int             field_4_last_column;
45
    
49
    
46
    private final static BitField   rowRelative = BitFieldFactory.getInstance(0x8000);
50
    private final static BitField   rowRelative = BitFieldFactory.getInstance(0x8000);
47
    private final static BitField   colRelative = BitFieldFactory.getInstance(0x4000);
51
    private final static BitField   colRelative = BitFieldFactory.getInstance(0x4000);
Lines 55-63 Link Here
55
        AreaReference ar = new AreaReference(arearef);
59
        AreaReference ar = new AreaReference(arearef);
56
        CellReference firstCell = ar.getFirstCell();
60
        CellReference firstCell = ar.getFirstCell();
57
        CellReference lastCell = ar.getLastCell();
61
        CellReference lastCell = ar.getLastCell();
58
        setFirstRow((short)firstCell.getRow());
62
        setFirstRow(firstCell.getRow());
59
        setFirstColumn(firstCell.getCol());
63
        setFirstColumn(firstCell.getCol());
60
        setLastRow((short)lastCell.getRow());
64
        setLastRow(lastCell.getRow());
61
        setLastColumn(lastCell.getCol());
65
        setLastColumn(lastCell.getCol());
62
        setFirstColRelative(!firstCell.isColAbsolute());
66
        setFirstColRelative(!firstCell.isColAbsolute());
63
        setLastColRelative(!lastCell.isColAbsolute());
67
        setLastColRelative(!lastCell.isColAbsolute());
Lines 65-71 Link Here
65
        setLastRowRelative(!lastCell.isRowAbsolute());        
69
        setLastRowRelative(!lastCell.isRowAbsolute());        
66
    }
70
    }
67
    
71
    
68
    public AreaPtg(short firstRow, short lastRow, short firstColumn, short lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
72
    public AreaPtg(int firstRow, int lastRow, int firstColumn, int lastColumn,
73
            boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
74
        
75
        checkColumnBounds(firstColumn);
76
        checkColumnBounds(lastColumn);
77
        checkRowBounds(firstRow);
78
        checkRowBounds(lastRow);
69
      setFirstRow(firstRow);
79
      setFirstRow(firstRow);
70
      setLastRow(lastRow);
80
      setLastRow(lastRow);
71
      setFirstColumn(firstColumn);
81
      setFirstColumn(firstColumn);
Lines 76-87 Link Here
76
      setLastColRelative(lastColRelative);
86
      setLastColRelative(lastColRelative);
77
    }    
87
    }    
78
88
89
    private static void checkColumnBounds(int colIx) {
90
        if((colIx & 0x0FF) != colIx) {
91
            throw new IllegalArgumentException("colIx (" + colIx + ") is out of range");
92
        }
93
    }
94
    private static void checkRowBounds(int rowIx) {
95
        if((rowIx & 0x0FFFF) != rowIx) {
96
            throw new IllegalArgumentException("rowIx (" + rowIx + ") is out of range");
97
        }
98
    }
99
79
    public AreaPtg(RecordInputStream in)
100
    public AreaPtg(RecordInputStream in)
80
    {
101
    {
81
        field_1_first_row    = in.readShort();
102
        field_1_first_row    = in.readUShort();
82
        field_2_last_row     = in.readShort();
103
        field_2_last_row     = in.readUShort();
83
        field_3_first_column = in.readShort();
104
        field_3_first_column = in.readUShort();
84
        field_4_last_column  = in.readShort();
105
        field_4_last_column  = in.readUShort();
85
        //System.out.println(toString());
106
        //System.out.println(toString());
86
    }
107
    }
87
    
108
    
Lines 110-119 Link Here
110
131
111
    public void writeBytes(byte [] array, int offset) {
132
    public void writeBytes(byte [] array, int offset) {
112
        array[offset] = (byte) (sid + ptgClass);
133
        array[offset] = (byte) (sid + ptgClass);
113
        LittleEndian.putShort(array,offset+1,field_1_first_row);
134
        LittleEndian.putShort(array,offset+1,(short)field_1_first_row);
114
        LittleEndian.putShort(array,offset+3,field_2_last_row);
135
        LittleEndian.putShort(array,offset+3,(short)field_2_last_row);
115
        LittleEndian.putShort(array,offset+5,field_3_first_column);
136
        LittleEndian.putShort(array,offset+5,(short)field_3_first_column);
116
        LittleEndian.putShort(array,offset+7,field_4_last_column);        
137
        LittleEndian.putShort(array,offset+7,(short)field_4_last_column);        
117
    }
138
    }
118
139
119
    public int getSize()
140
    public int getSize()
Lines 124-165 Link Here
124
    /**
145
    /**
125
     * @return the first row in the area
146
     * @return the first row in the area
126
     */
147
     */
127
    public short getFirstRow()
148
    public int getFirstRow()
128
    {
149
    {
129
        return field_1_first_row;
150
        return field_1_first_row;
130
    }
151
    }
131
152
132
    /**
153
    /**
133
     * sets the first row
154
     * sets the first row
134
     * @param row number (0-based)
155
     * @param rowIx number (0-based)
135
     */
156
     */
136
    public void setFirstRow(short row)
157
    public void setFirstRow(int rowIx) {
137
    {
158
        checkRowBounds(rowIx);
138
        field_1_first_row = row;
159
        field_1_first_row = rowIx;
139
    }
160
    }
140
161
141
    /**
162
    /**
142
     * @return last row in the range (x2 in x1,y1-x2,y2)
163
     * @return last row in the range (x2 in x1,y1-x2,y2)
143
     */
164
     */
144
    public short getLastRow()
165
    public int getLastRow()
145
    {
166
    {
146
        return field_2_last_row;
167
        return field_2_last_row;
147
    }
168
    }
148
169
149
    /**
170
    /**
150
     * @param row last row number in the area 
171
     * @param rowIx last row number in the area 
151
     */
172
     */
152
    public void setLastRow(short row)
173
    public void setLastRow(int rowIx) {
153
    {
174
        checkRowBounds(rowIx);
154
        field_2_last_row = row;
175
        field_2_last_row = rowIx;
155
    }
176
    }
156
177
157
    /**
178
    /**
158
     * @return the first column number in the area.
179
     * @return the first column number in the area.
159
     */
180
     */
160
    public short getFirstColumn()
181
    public int getFirstColumn()
161
    {
182
    {
162
        return columnMask.getShortValue(field_3_first_column);
183
        return columnMask.getValue(field_3_first_column);
163
    }
184
    }
164
185
165
    /**
186
    /**
Lines 167-173 Link Here
167
     */
188
     */
168
    public short getFirstColumnRaw()
189
    public short getFirstColumnRaw()
169
    {
190
    {
170
        return field_3_first_column;
191
        return (short) field_3_first_column; // TODO
171
    }
192
    }
172
193
173
    /**
194
    /**
Lines 183-189 Link Here
183
     * @param rel is relative or not.
204
     * @param rel is relative or not.
184
     */
205
     */
185
    public void setFirstRowRelative(boolean rel) {
206
    public void setFirstRowRelative(boolean rel) {
186
        field_3_first_column=rowRelative.setShortBoolean(field_3_first_column,rel);
207
        field_3_first_column=rowRelative.setBoolean(field_3_first_column,rel);
187
    }
208
    }
188
209
189
    /**
210
    /**
Lines 198-218 Link Here
198
     * set whether the first column is relative 
219
     * set whether the first column is relative 
199
     */
220
     */
200
    public void setFirstColRelative(boolean rel) {
221
    public void setFirstColRelative(boolean rel) {
201
        field_3_first_column=colRelative.setShortBoolean(field_3_first_column,rel);
222
        field_3_first_column=colRelative.setBoolean(field_3_first_column,rel);
202
    }
223
    }
203
224
204
    /**
225
    /**
205
     * set the first column in the area
226
     * set the first column in the area
206
     */
227
     */
207
    public void setFirstColumn(short column)
228
    public void setFirstColumn(int colIx) {
208
    {
229
        checkColumnBounds(colIx);
209
    	field_3_first_column=columnMask.setShortValue(field_3_first_column, column);
230
    	field_3_first_column=columnMask.setValue(field_3_first_column, colIx);
210
    }
231
    }
211
232
212
    /**
233
    /**
213
     * set the first column irespective of the bitmasks
234
     * set the first column irespective of the bitmasks
214
     */
235
     */
215
    public void setFirstColumnRaw(short column)
236
    public void setFirstColumnRaw(int column)
216
    {
237
    {
217
        field_3_first_column = column;
238
        field_3_first_column = column;
218
    }
239
    }
Lines 220-228 Link Here
220
    /**
241
    /**
221
     * @return lastcolumn in the area
242
     * @return lastcolumn in the area
222
     */
243
     */
223
    public short getLastColumn()
244
    public int getLastColumn()
224
    {
245
    {
225
        return columnMask.getShortValue(field_4_last_column);
246
        return columnMask.getValue(field_4_last_column);
226
    }
247
    }
227
248
228
    /**
249
    /**
Lines 230-236 Link Here
230
     */
251
     */
231
    public short getLastColumnRaw()
252
    public short getLastColumnRaw()
232
    {
253
    {
233
        return field_4_last_column;
254
        return (short) field_4_last_column;
234
    }
255
    }
235
256
236
    /**
257
    /**
Lines 247-253 Link Here
247
     * <code>false</code>
268
     * <code>false</code>
248
     */
269
     */
249
    public void setLastRowRelative(boolean rel) {
270
    public void setLastRowRelative(boolean rel) {
250
        field_4_last_column=rowRelative.setShortBoolean(field_4_last_column,rel);
271
        field_4_last_column=rowRelative.setBoolean(field_4_last_column,rel);
251
    }
272
    }
252
273
253
    /**
274
    /**
Lines 262-277 Link Here
262
     * set whether the last column should be relative or not
283
     * set whether the last column should be relative or not
263
     */
284
     */
264
    public void setLastColRelative(boolean rel) {
285
    public void setLastColRelative(boolean rel) {
265
        field_4_last_column=colRelative.setShortBoolean(field_4_last_column,rel);
286
        field_4_last_column=colRelative.setBoolean(field_4_last_column,rel);
266
    }
287
    }
267
    
288
    
268
289
269
    /**
290
    /**
270
     * set the last column in the area
291
     * set the last column in the area
271
     */
292
     */
272
    public void setLastColumn(short column)
293
    public void setLastColumn(int colIx) {
273
    {
294
        checkColumnBounds(colIx);
274
    	field_4_last_column=columnMask.setShortValue(field_4_last_column, column);
295
    	field_4_last_column=columnMask.setValue(field_4_last_column, colIx);
275
    }
296
    }
276
297
277
    /**
298
    /**
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java (-49 / +49 lines)
Lines 41-50 Link Here
41
	public final static byte sid = 0x3b;
41
	public final static byte sid = 0x3b;
42
	private final static int SIZE = 11; // 10 + 1 for Ptg
42
	private final static int SIZE = 11; // 10 + 1 for Ptg
43
	private short field_1_index_extern_sheet;
43
	private short field_1_index_extern_sheet;
44
	private short field_2_first_row;
44
	private int field_2_first_row;
45
	private short field_3_last_row;
45
	private int field_3_last_row;
46
	private short field_4_first_column;
46
	private int field_4_first_column;
47
	private short field_5_last_column;
47
	private int field_5_last_column;
48
48
49
	private BitField rowRelative = BitFieldFactory.getInstance( 0x8000 );
49
	private BitField rowRelative = BitFieldFactory.getInstance( 0x8000 );
50
	private BitField colRelative = BitFieldFactory.getInstance( 0x4000 );
50
	private BitField colRelative = BitFieldFactory.getInstance( 0x4000 );
Lines 64-90 Link Here
64
	public Area3DPtg(RecordInputStream in)
64
	public Area3DPtg(RecordInputStream in)
65
	{
65
	{
66
		field_1_index_extern_sheet = in.readShort();
66
		field_1_index_extern_sheet = in.readShort();
67
		field_2_first_row = in.readShort();
67
		field_2_first_row = in.readUShort();
68
		field_3_last_row = in.readShort();
68
		field_3_last_row = in.readUShort();
69
		field_4_first_column = in.readShort();
69
		field_4_first_column = in.readUShort();
70
		field_5_last_column = in.readShort();
70
		field_5_last_column = in.readUShort();
71
	}
71
	}
72
72
73
	public Area3DPtg(short firstRow, short lastRow, short firstColumn, short lastColumn,
73
	public Area3DPtg(short firstRow, short lastRow, short firstColumn, short lastColumn,
74
	        boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative,
74
			boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative,
75
	        short externalSheetIndex) {
75
			short externalSheetIndex) {
76
	      setFirstRow(firstRow);
76
		  setFirstRow(firstRow);
77
	      setLastRow(lastRow);
77
		  setLastRow(lastRow);
78
	      setFirstColumn(firstColumn);
78
		  setFirstColumn(firstColumn);
79
	      setLastColumn(lastColumn);
79
		  setLastColumn(lastColumn);
80
	      setFirstRowRelative(firstRowRelative);
80
		  setFirstRowRelative(firstRowRelative);
81
	      setLastRowRelative(lastRowRelative);
81
		  setLastRowRelative(lastRowRelative);
82
	      setFirstColRelative(firstColRelative);
82
		  setFirstColRelative(firstColRelative);
83
	      setLastColRelative(lastColRelative);
83
		  setLastColRelative(lastColRelative);
84
	      setExternSheetIndex(externalSheetIndex);
84
		  setExternSheetIndex(externalSheetIndex);
85
    }
85
	}
86
86
87
    public String toString()
87
	public String toString()
88
	{
88
	{
89
		StringBuffer buffer = new StringBuffer();
89
		StringBuffer buffer = new StringBuffer();
90
90
Lines 99-105 Link Here
99
		buffer.append( "lastColRowRel = "
99
		buffer.append( "lastColRowRel = "
100
				+ isLastRowRelative() ).append( "\n" );
100
				+ isLastRowRelative() ).append( "\n" );
101
		buffer.append( "firstColRel   = " + isFirstColRelative() ).append( "\n" );
101
		buffer.append( "firstColRel   = " + isFirstColRelative() ).append( "\n" );
102
		buffer.append( "lastColRel    = " + isLastColRelative() ).append( "\n" );
102
		buffer.append( "lastColRel	= " + isLastColRelative() ).append( "\n" );
103
		return buffer.toString();
103
		return buffer.toString();
104
	}
104
	}
105
105
Lines 107-116 Link Here
107
	{
107
	{
108
		array[0 + offset] = (byte) ( sid + ptgClass );
108
		array[0 + offset] = (byte) ( sid + ptgClass );
109
		LittleEndian.putShort( array, 1 + offset, getExternSheetIndex() );
109
		LittleEndian.putShort( array, 1 + offset, getExternSheetIndex() );
110
		LittleEndian.putShort( array, 3 + offset, getFirstRow() );
110
		LittleEndian.putShort( array, 3 + offset, (short)getFirstRow() );
111
		LittleEndian.putShort( array, 5 + offset, getLastRow() );
111
		LittleEndian.putShort( array, 5 + offset, (short)getLastRow() );
112
		LittleEndian.putShort( array, 7 + offset, getFirstColumnRaw() );
112
		LittleEndian.putShort( array, 7 + offset, (short)getFirstColumnRaw() );
113
		LittleEndian.putShort( array, 9 + offset, getLastColumnRaw() );
113
		LittleEndian.putShort( array, 9 + offset, (short)getLastColumnRaw() );
114
	}
114
	}
115
115
116
	public int getSize()
116
	public int getSize()
Lines 128-159 Link Here
128
		field_1_index_extern_sheet = index;
128
		field_1_index_extern_sheet = index;
129
	}
129
	}
130
130
131
	public short getFirstRow()
131
	public int getFirstRow()
132
	{
132
	{
133
		return field_2_first_row;
133
		return field_2_first_row;
134
	}
134
	}
135
135
136
	public void setFirstRow( short row )
136
	public void setFirstRow( int row )
137
	{
137
	{
138
		field_2_first_row = row;
138
		field_2_first_row = row;
139
	}
139
	}
140
140
141
	public short getLastRow()
141
	public int getLastRow()
142
	{
142
	{
143
		return field_3_last_row;
143
		return field_3_last_row;
144
	}
144
	}
145
145
146
	public void setLastRow( short row )
146
	public void setLastRow( int row )
147
	{
147
	{
148
		field_3_last_row = row;
148
		field_3_last_row = row;
149
	}
149
	}
150
150
151
	public short getFirstColumn()
151
	public int getFirstColumn()
152
	{
152
	{
153
		return (short) ( field_4_first_column & 0xFF );
153
		return field_4_first_column & 0xFF;
154
	}
154
	}
155
155
156
	public short getFirstColumnRaw()
156
	public int getFirstColumnRaw()
157
	{
157
	{
158
		return field_4_first_column;
158
		return field_4_first_column;
159
	}
159
	}
Lines 179-190 Link Here
179
		field_4_first_column = column;
179
		field_4_first_column = column;
180
	}
180
	}
181
181
182
	public short getLastColumn()
182
	public int getLastColumn()
183
	{
183
	{
184
		return (short) ( field_5_last_column & 0xFF );
184
		return field_5_last_column & 0xFF;
185
	}
185
	}
186
186
187
	public short getLastColumnRaw()
187
	public int getLastColumnRaw()
188
	{
188
	{
189
		return field_5_last_column;
189
		return field_5_last_column;
190
	}
190
	}
Lines 216-222 Link Here
216
	 */
216
	 */
217
	public void setFirstRowRelative( boolean rel )
217
	public void setFirstRowRelative( boolean rel )
218
	{
218
	{
219
		field_4_first_column = rowRelative.setShortBoolean( field_4_first_column, rel );
219
		field_4_first_column = rowRelative.setBoolean( field_4_first_column, rel );
220
	}
220
	}
221
221
222
	/**
222
	/**
Lines 224-230 Link Here
224
	 */
224
	 */
225
	public void setFirstColRelative( boolean rel )
225
	public void setFirstColRelative( boolean rel )
226
	{
226
	{
227
		field_4_first_column = colRelative.setShortBoolean( field_4_first_column, rel );
227
		field_4_first_column = colRelative.setBoolean( field_4_first_column, rel );
228
	}
228
	}
229
229
230
	/**
230
	/**
Lines 233-239 Link Here
233
	 */
233
	 */
234
	public void setLastRowRelative( boolean rel )
234
	public void setLastRowRelative( boolean rel )
235
	{
235
	{
236
		field_5_last_column = rowRelative.setShortBoolean( field_5_last_column, rel );
236
		field_5_last_column = rowRelative.setBoolean( field_5_last_column, rel );
237
	}
237
	}
238
238
239
	/**
239
	/**
Lines 241-247 Link Here
241
	 */
241
	 */
242
	public void setLastColRelative( boolean rel )
242
	public void setLastColRelative( boolean rel )
243
	{
243
	{
244
		field_5_last_column = colRelative.setShortBoolean( field_5_last_column, rel );
244
		field_5_last_column = colRelative.setBoolean( field_5_last_column, rel );
245
	}
245
	}
246
246
247
247
Lines 259-278 Link Here
259
		CellReference frstCell = ar.getFirstCell();
259
		CellReference frstCell = ar.getFirstCell();
260
		CellReference lastCell = ar.getLastCell();
260
		CellReference lastCell = ar.getLastCell();
261
261
262
		setFirstRow(    (short) frstCell.getRow() );
262
		setFirstRow(	(short) frstCell.getRow() );
263
		setFirstColumn(         frstCell.getCol() );
263
		setFirstColumn(		 frstCell.getCol() );
264
		setLastRow(     (short) lastCell.getRow() );
264
		setLastRow(	 (short) lastCell.getRow() );
265
		setLastColumn(          lastCell.getCol() );
265
		setLastColumn(		  lastCell.getCol() );
266
		setFirstColRelative( !frstCell.isColAbsolute() );
266
		setFirstColRelative( !frstCell.isColAbsolute() );
267
		setLastColRelative(  !lastCell.isColAbsolute() );
267
		setLastColRelative(  !lastCell.isColAbsolute() );
268
		setFirstRowRelative( !frstCell.isRowAbsolute() );
268
		setFirstRowRelative( !frstCell.isRowAbsolute() );
269
		setLastRowRelative(  !lastCell.isRowAbsolute() );
269
		setLastRowRelative(  !lastCell.isRowAbsolute() );
270
	}
270
	}
271
271
272
    /**
272
	/**
273
     * @return text representation of this area reference that can be used in text
273
	 * @return text representation of this area reference that can be used in text
274
     *  formulas. The sheet name will get properly delimited if required.
274
	 *  formulas. The sheet name will get properly delimited if required.
275
     */
275
	 */
276
	public String toFormulaString(Workbook book)
276
	public String toFormulaString(Workbook book)
277
	{
277
	{
278
		// First do the sheet name
278
		// First do the sheet name
Lines 303-309 Link Here
303
		ptg.field_3_last_row = field_3_last_row;
303
		ptg.field_3_last_row = field_3_last_row;
304
		ptg.field_4_first_column = field_4_first_column;
304
		ptg.field_4_first_column = field_4_first_column;
305
		ptg.field_5_last_column = field_5_last_column;
305
		ptg.field_5_last_column = field_5_last_column;
306
            ptg.setClass(ptgClass);
306
		ptg.setClass(ptgClass);
307
		return ptg;
307
		return ptg;
308
	}
308
	}
309
309
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/record/formula/AreaI.java (-4 / +4 lines)
Lines 24-45 Link Here
24
    /**
24
    /**
25
     * @return the first row in the area
25
     * @return the first row in the area
26
     */
26
     */
27
    public short getFirstRow();
27
    public int getFirstRow();
28
28
29
    /**
29
    /**
30
     * @return last row in the range (x2 in x1,y1-x2,y2)
30
     * @return last row in the range (x2 in x1,y1-x2,y2)
31
     */
31
     */
32
    public short getLastRow();
32
    public int getLastRow();
33
    
33
    
34
    /**
34
    /**
35
     * @return the first column number in the area.
35
     * @return the first column number in the area.
36
     */
36
     */
37
    public short getFirstColumn();
37
    public int getFirstColumn();
38
    
38
    
39
    /**
39
    /**
40
     * @return lastcolumn in the area
40
     * @return lastcolumn in the area
41
     */
41
     */
42
    public short getLastColumn();
42
    public int getLastColumn();
43
    
43
    
44
    /**
44
    /**
45
     * @return isrelative first column to relative or not
45
     * @return isrelative first column to relative or not
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/record/formula/RefAPtg.java (-14 / +2 lines)
Lines 1-4 Link Here
1
2
/* ====================================================================
1
/* ====================================================================
3
   Licensed to the Apache Software Foundation (ASF) under one or more
2
   Licensed to the Apache Software Foundation (ASF) under one or more
4
   contributor license agreements.  See the NOTICE file distributed with
3
   contributor license agreements.  See the NOTICE file distributed with
Lines 16-49 Link Here
16
   limitations under the License.
15
   limitations under the License.
17
==================================================================== */
16
==================================================================== */
18
17
19
/*
20
 * ValueReferencePtg.java
21
 *
22
 * Created on November 21, 2001, 5:27 PM
23
 */
24
package org.apache.poi.hssf.record.formula;
18
package org.apache.poi.hssf.record.formula;
25
19
26
import org.apache.poi.util.LittleEndian;
27
import org.apache.poi.util.BitField;
28
29
import org.apache.poi.hssf.record.RecordInputStream;
20
import org.apache.poi.hssf.record.RecordInputStream;
30
import org.apache.poi.hssf.util.CellReference;
31
import org.apache.poi.hssf.model.Workbook;
32
21
33
/**
22
/**
34
 * RefNAPtg
23
 * RefNAPtg
35
 * @author Jason Height (jheight at chariot dot net dot au)
24
 * @author Jason Height (jheight at chariot dot net dot au)
36
 */
25
 */
37
26
38
public class RefAPtg extends ReferencePtg
27
public final class RefAPtg extends ReferencePtg {
39
{
40
    public final static byte sid  = 0x64;
28
    public final static byte sid  = 0x64;
41
29
42
    protected RefAPtg() {
30
    protected RefAPtg() {
43
      super();
31
      super();
44
    }
32
    }
45
33
46
    public RefAPtg(short row, short column, boolean isRowRelative, boolean isColumnRelative) {
34
    public RefAPtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
47
      super(row, column, isRowRelative, isColumnRelative);
35
      super(row, column, isRowRelative, isColumnRelative);
48
    }
36
    }
49
37
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/record/formula/RefVPtg.java (-10 / +2 lines)
Lines 1-4 Link Here
1
2
/* ====================================================================
1
/* ====================================================================
3
   Licensed to the Apache Software Foundation (ASF) under one or more
2
   Licensed to the Apache Software Foundation (ASF) under one or more
4
   contributor license agreements.  See the NOTICE file distributed with
3
   contributor license agreements.  See the NOTICE file distributed with
Lines 18-44 Link Here
18
17
19
package org.apache.poi.hssf.record.formula;
18
package org.apache.poi.hssf.record.formula;
20
19
21
import org.apache.poi.util.LittleEndian;
22
import org.apache.poi.util.BitField;
23
24
import org.apache.poi.hssf.record.RecordInputStream;
20
import org.apache.poi.hssf.record.RecordInputStream;
25
import org.apache.poi.hssf.util.CellReference;
26
import org.apache.poi.hssf.model.Workbook;
27
21
28
/**
22
/**
29
 * RefVPtg
23
 * RefVPtg
30
 * @author Jason Height (jheight at chariot dot net dot au)
24
 * @author Jason Height (jheight at chariot dot net dot au)
31
 */
25
 */
32
26
public final class RefVPtg extends ReferencePtg {
33
public class RefVPtg extends ReferencePtg
34
{
35
  public final static byte sid  = 0x44;
27
  public final static byte sid  = 0x44;
36
28
37
  protected RefVPtg() {
29
  protected RefVPtg() {
38
    super();
30
    super();
39
  }
31
  }
40
32
41
  public RefVPtg(short row, short column, boolean isRowRelative, boolean isColumnRelative) {
33
  public RefVPtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
42
    super(row, column, isRowRelative, isColumnRelative);
34
    super(row, column, isRowRelative, isColumnRelative);
43
  }
35
  }
44
36
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java (-43 / +31 lines)
Lines 31-56 Link Here
31
 * @author Jason Height (jheight at chariot dot net dot au)
31
 * @author Jason Height (jheight at chariot dot net dot au)
32
 */
32
 */
33
33
34
public class ReferencePtg extends Ptg
34
public class ReferencePtg extends Ptg {
35
{
36
    private final static int SIZE = 5;
35
    private final static int SIZE = 5;
37
    public final static byte sid  = 0x24;
36
    public final static byte sid  = 0x24;
38
    private final static int MAX_ROW_NUMBER = 65536;             
37
    private final static int MAX_ROW_NUMBER = 65536;             
39
    //public final static byte sid = 0x44;
40
38
41
   /** 
39
   /** The row index - zero based unsigned 16 bit value */
42
     * The row number, between 0 and 65535, but stored as a signed
40
    private int            field_1_row;
43
     *  short between -32767 and 32768.
41
    /** Field 2 
44
     * Take care about which version you fetch back!
42
     * - lower 8 bits is the zero based unsigned byte column index 
43
     * - bit 16 - isRowRelative
44
     * - bit 15 - isColumnRelative 
45
     */
45
     */
46
    private short            field_1_row;
46
    private int            field_2_col;
47
    /**
47
    private static final BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
48
     * The column number, between 0 and ??
48
    private static final BitField         colRelative = BitFieldFactory.getInstance(0x4000);
49
     */
49
    private static final BitField         column      = BitFieldFactory.getInstance(0x00FF);
50
    private short            field_2_col;
51
    private BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
52
    private BitField         colRelative = BitFieldFactory.getInstance(0x4000);
53
    private BitField         column      = BitFieldFactory.getInstance(0x3FFF);
54
50
55
    protected ReferencePtg() {
51
    protected ReferencePtg() {
56
      //Required for clone methods
52
      //Required for clone methods
Lines 62-74 Link Here
62
     */
58
     */
63
    public ReferencePtg(String cellref) {
59
    public ReferencePtg(String cellref) {
64
        CellReference c= new CellReference(cellref);
60
        CellReference c= new CellReference(cellref);
65
        setRow((short) c.getRow());
61
        setRow(c.getRow());
66
        setColumn((short) c.getCol());
62
        setColumn(c.getCol());
67
        setColRelative(!c.isColAbsolute());
63
        setColRelative(!c.isColAbsolute());
68
        setRowRelative(!c.isRowAbsolute());
64
        setRowRelative(!c.isRowAbsolute());
69
    }
65
    }
70
    
66
    
71
    public ReferencePtg(short row, short column, boolean isRowRelative, boolean isColumnRelative) {
67
    public ReferencePtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
72
      setRow(row);
68
      setRow(row);
73
      setColumn(column);
69
      setColumn(column);
74
      setRowRelative(isRowRelative);
70
      setRowRelative(isRowRelative);
Lines 79-86 Link Here
79
75
80
    public ReferencePtg(RecordInputStream in)
76
    public ReferencePtg(RecordInputStream in)
81
    {
77
    {
82
        field_1_row = in.readShort();
78
        field_1_row = in.readUShort();
83
        field_2_col = in.readShort();
79
        field_2_col = in.readUShort();
84
    }
80
    }
85
    
81
    
86
    public String getRefPtgName() {
82
    public String getRefPtgName() {
Lines 104-136 Link Here
104
    {
100
    {
105
        array[offset] = (byte) (sid + ptgClass);
101
        array[offset] = (byte) (sid + ptgClass);
106
102
107
        LittleEndian.putShort(array,offset+1,field_1_row);
103
        LittleEndian.putShort(array, offset+1, (short)field_1_row);
108
        LittleEndian.putShort(array,offset+3,field_2_col);
104
        LittleEndian.putShort(array, offset+3, (short)field_2_col);
109
    }
105
    }
110
106
111
    public void setRow(short row)
112
    {
113
        field_1_row = row;
114
    }
115
    public void setRow(int row)
107
    public void setRow(int row)
116
    {
108
    {
117
        if(row < 0 || row >= MAX_ROW_NUMBER) {
109
        if(row < 0 || row >= MAX_ROW_NUMBER) {
118
           throw new IllegalArgumentException("The row number, when specified as an integer, must be between 0 and " + MAX_ROW_NUMBER);
110
           throw new IllegalArgumentException("The row number, when specified as an integer, must be between 0 and " + MAX_ROW_NUMBER);
119
        }
111
        }
120
        
112
        field_1_row = row;
121
        // Save, wrapping as needed
122
        if(row > Short.MAX_VALUE) {
123
        	field_1_row = (short)(row - MAX_ROW_NUMBER);
124
        } else {
125
        	field_1_row = (short)row;
126
        }
127
    }
113
    }
128
114
129
    /**
115
    /**
130
     * Returns the row number as a short, which will be
116
     * Returns the row number as a short, which will be
131
     *  wrapped (negative) for values between 32769 and 65535
117
     *  wrapped (negative) for values between 32769 and 65535
132
     */
118
     */
133
    public short getRow()
119
    public int getRow()
134
    {
120
    {
135
        return field_1_row;
121
        return field_1_row;
136
    }
122
    }
Lines 151-157 Link Here
151
    }
137
    }
152
    
138
    
153
    public void setRowRelative(boolean rel) {
139
    public void setRowRelative(boolean rel) {
154
        field_2_col=rowRelative.setShortBoolean(field_2_col,rel);
140
        field_2_col=rowRelative.setBoolean(field_2_col,rel);
155
    }
141
    }
156
    
142
    
157
    public boolean isColRelative()
143
    public boolean isColRelative()
Lines 160-186 Link Here
160
    }
146
    }
161
    
147
    
162
    public void setColRelative(boolean rel) {
148
    public void setColRelative(boolean rel) {
163
        field_2_col=colRelative.setShortBoolean(field_2_col,rel);
149
        field_2_col=colRelative.setBoolean(field_2_col,rel);
164
    }
150
    }
165
151
166
    public void setColumnRaw(short col)
152
    public void setColumnRaw(int col)
167
    {
153
    {
168
        field_2_col = col;
154
        field_2_col = col;
169
    }
155
    }
170
156
171
    public short getColumnRaw()
157
    public int getColumnRaw()
172
    {
158
    {
173
        return field_2_col;
159
        return field_2_col;
174
    }
160
    }
175
161
176
    public void setColumn(short col)
162
    public void setColumn(int col)
177
    {
163
    {
178
    	field_2_col = column.setShortValue(field_2_col, col);
164
        if(col < 0 || col > 0x100) {
165
            throw new IllegalArgumentException("Specified colIx (" + col + ") is out of range");
166
        }
167
    	field_2_col = column.setValue(field_2_col, col);
179
    }
168
    }
180
169
181
    public short getColumn()
170
    public int getColumn() {
182
    {
171
    	return column.getValue(field_2_col);
183
    	return column.getShortValue(field_2_col);
184
    }
172
    }
185
173
186
    public int getSize()
174
    public int getSize()
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java (-20 / +23 lines)
Lines 18-33 Link Here
18
18
19
package org.apache.poi.hssf.record.formula;
19
package org.apache.poi.hssf.record.formula;
20
20
21
import org.apache.poi.util.LittleEndian;
21
import org.apache.poi.hssf.model.Workbook;
22
22
import org.apache.poi.hssf.record.RecordInputStream;
23
import org.apache.poi.hssf.util.CellReference;
23
import org.apache.poi.hssf.util.RangeAddress;
24
import org.apache.poi.hssf.util.RangeAddress;
24
import org.apache.poi.hssf.util.CellReference;
25
import org.apache.poi.hssf.util.SheetReferences;
25
import org.apache.poi.hssf.util.SheetReferences;
26
import org.apache.poi.hssf.model.Workbook;
27
import org.apache.poi.util.BitField;
26
import org.apache.poi.util.BitField;
28
import org.apache.poi.util.BitFieldFactory;
27
import org.apache.poi.util.BitFieldFactory;
29
import org.apache.poi.hssf.model.Workbook;
28
import org.apache.poi.util.LittleEndian;
30
import org.apache.poi.hssf.record.RecordInputStream;
31
29
32
/**
30
/**
33
 * Title:        Reference 3D Ptg <P>
31
 * Title:        Reference 3D Ptg <P>
Lines 42-49 Link Here
42
    public final static byte sid  = 0x3a;
40
    public final static byte sid  = 0x3a;
43
    private final static int  SIZE = 7; // 6 + 1 for Ptg
41
    private final static int  SIZE = 7; // 6 + 1 for Ptg
44
    private short             field_1_index_extern_sheet;
42
    private short             field_1_index_extern_sheet;
45
    private short             field_2_row;
43
    /** The row index - zero based unsigned 16 bit value */
46
    private short             field_3_column;
44
    private int            field_2_row;
45
    /** Field 2 
46
     * - lower 8 bits is the zero based unsigned byte column index 
47
     * - bit 16 - isRowRelative
48
     * - bit 15 - isColumnRelative 
49
     */
50
    private int             field_3_column;
47
    private BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
51
    private BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
48
    private BitField         colRelative = BitFieldFactory.getInstance(0x4000);
52
    private BitField         colRelative = BitFieldFactory.getInstance(0x4000);
49
53
Lines 58-65 Link Here
58
    
62
    
59
    public Ref3DPtg(String cellref, short externIdx ) {
63
    public Ref3DPtg(String cellref, short externIdx ) {
60
        CellReference c= new CellReference(cellref);
64
        CellReference c= new CellReference(cellref);
61
        setRow((short) c.getRow());
65
        setRow(c.getRow());
62
        setColumn((short) c.getCol());
66
        setColumn(c.getCol());
63
        setColRelative(!c.isColAbsolute());
67
        setColRelative(!c.isColAbsolute());
64
        setRowRelative(!c.isRowAbsolute());   
68
        setRowRelative(!c.isRowAbsolute());   
65
        setExternSheetIndex(externIdx);
69
        setExternSheetIndex(externIdx);
Lines 81-88 Link Here
81
    public void writeBytes(byte [] array, int offset) {
85
    public void writeBytes(byte [] array, int offset) {
82
        array[ 0 + offset ] = (byte) (sid + ptgClass);
86
        array[ 0 + offset ] = (byte) (sid + ptgClass);
83
        LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
87
        LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
84
        LittleEndian.putShort(array, 3 + offset , getRow());
88
        LittleEndian.putShort(array, 3 + offset , (short)getRow());
85
        LittleEndian.putShort(array, 5 + offset , getColumnRaw());
89
        LittleEndian.putShort(array, 5 + offset , (short)getColumnRaw());
86
    }
90
    }
87
91
88
    public int getSize() {
92
    public int getSize() {
Lines 97-115 Link Here
97
        field_1_index_extern_sheet = index;
101
        field_1_index_extern_sheet = index;
98
    }
102
    }
99
103
100
    public short getRow() {
104
    public int getRow() {
101
        return field_2_row;
105
        return field_2_row;
102
    }
106
    }
103
107
104
    public void setRow(short row) {
108
    public void setRow(int row) {
105
        field_2_row = row;
109
        field_2_row = row;
106
    }
110
    }
107
111
108
    public short getColumn() {
112
    public int getColumn() {
109
        return ( short ) (field_3_column & 0xFF);
113
        return field_3_column & 0xFF;
110
    }
114
    }
111
115
112
    public short getColumnRaw() {
116
    public int getColumnRaw() {
113
        return field_3_column;
117
        return field_3_column;
114
    }
118
    }
115
119
Lines 119-125 Link Here
119
    }
123
    }
120
    
124
    
121
    public void setRowRelative(boolean rel) {
125
    public void setRowRelative(boolean rel) {
122
        field_3_column=rowRelative.setShortBoolean(field_3_column,rel);
126
        field_3_column=rowRelative.setBoolean(field_3_column,rel);
123
    }
127
    }
124
    
128
    
125
    public boolean isColRelative()
129
    public boolean isColRelative()
Lines 128-134 Link Here
128
    }
132
    }
129
    
133
    
130
    public void setColRelative(boolean rel) {
134
    public void setColRelative(boolean rel) {
131
        field_3_column=colRelative.setShortBoolean(field_3_column,rel);
135
        field_3_column=colRelative.setBoolean(field_3_column,rel);
132
    }
136
    }
133
    public void setColumn(short column) {
137
    public void setColumn(short column) {
134
        field_3_column &= 0xFF00;
138
        field_3_column &= 0xFF00;
Lines 197-201 Link Here
197
     ptg.setClass(ptgClass);
201
     ptg.setClass(ptgClass);
198
     return ptg;
202
     return ptg;
199
   }
203
   }
200
201
}
204
}
(-)C:\josh\source\poi\subv\trunk/src/java/org/apache/poi/hssf/record/formula/AreaAPtg.java (-4 / +2 lines)
Lines 36-51 Link Here
36
 * @author Jason Height (jheight at chariot dot net dot au)
36
 * @author Jason Height (jheight at chariot dot net dot au)
37
 */
37
 */
38
38
39
public class AreaAPtg
39
public final class AreaAPtg extends AreaPtg {
40
    extends AreaPtg
41
{
42
    public final static short sid  = 0x65;
40
    public final static short sid  = 0x65;
43
41
44
    protected AreaAPtg() {
42
    protected AreaAPtg() {
45
      //Required for clone methods
43
      //Required for clone methods
46
    }
44
    }
47
45
48
    public AreaAPtg(short firstRow, short lastRow, short firstColumn, short lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
46
    public AreaAPtg(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
49
      super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
47
      super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
50
    }
48
    }
51
49
(-)C:\josh\source\poi\subv\trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java (-39 / +36 lines)
Lines 14-23 Link Here
14
* See the License for the specific language governing permissions and
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
15
* limitations under the License.
16
*/
16
*/
17
/*
17
18
 * Created on May 5, 2005
19
 *
20
 */
21
package org.apache.poi.hssf.usermodel;
18
package org.apache.poi.hssf.usermodel;
22
19
23
import java.lang.reflect.Constructor;
20
import java.lang.reflect.Constructor;
Lines 420-439 Link Here
420
            }
417
            }
421
            else if (ptg instanceof ReferencePtg) {
418
            else if (ptg instanceof ReferencePtg) {
422
                ReferencePtg refPtg = (ReferencePtg) ptg;
419
                ReferencePtg refPtg = (ReferencePtg) ptg;
423
                short colnum = refPtg.getColumn();
420
                int colIx = refPtg.getColumn();
424
                short rownum = refPtg.getRow();
421
                int rowIx = refPtg.getRow();
425
                HSSFRow row = sheet.getRow(rownum);
422
                HSSFRow row = sheet.getRow(rowIx);
426
                HSSFCell cell = (row != null) ? row.getCell(colnum) : null;
423
                HSSFCell cell = (row != null) ? row.getCell(colIx) : null;
427
                stack.push(createRef2DEval(refPtg, cell, row, sheet, workbook));
424
                stack.push(createRef2DEval(refPtg, cell, row, sheet, workbook));
428
            }
425
            }
429
            else if (ptg instanceof Ref3DPtg) {
426
            else if (ptg instanceof Ref3DPtg) {
430
                Ref3DPtg refPtg = (Ref3DPtg) ptg;
427
                Ref3DPtg refPtg = (Ref3DPtg) ptg;
431
                short colnum = refPtg.getColumn();
428
                int colIx = refPtg.getColumn();
432
                short rownum = refPtg.getRow();
429
                int rowIx = refPtg.getRow();
433
                Workbook wb = workbook.getWorkbook();
430
                Workbook wb = workbook.getWorkbook();
434
                HSSFSheet xsheet = workbook.getSheetAt(wb.getSheetIndexFromExternSheetIndex(refPtg.getExternSheetIndex()));
431
                HSSFSheet xsheet = workbook.getSheetAt(wb.getSheetIndexFromExternSheetIndex(refPtg.getExternSheetIndex()));
435
                HSSFRow row = xsheet.getRow(rownum);
432
                HSSFRow row = xsheet.getRow(rowIx);
436
                HSSFCell cell = (row != null) ? row.getCell(colnum) : null;
433
                HSSFCell cell = (row != null) ? row.getCell(colIx) : null;
437
                stack.push(createRef3DEval(refPtg, cell, row, xsheet, workbook));
434
                stack.push(createRef3DEval(refPtg, cell, row, xsheet, workbook));
438
            }
435
            }
439
            else if (ptg instanceof AreaPtg) {
436
            else if (ptg instanceof AreaPtg) {
Lines 506-515 Link Here
506
    }
503
    }
507
    
504
    
508
    public static AreaEval evaluateAreaPtg(HSSFSheet sheet, HSSFWorkbook workbook, AreaPtg ap) {
505
    public static AreaEval evaluateAreaPtg(HSSFSheet sheet, HSSFWorkbook workbook, AreaPtg ap) {
509
        short row0 = ap.getFirstRow();
506
        int row0 = ap.getFirstRow();
510
        short col0 = ap.getFirstColumn();
507
        int col0 = ap.getFirstColumn();
511
        short row1 = ap.getLastRow();
508
        int row1 = ap.getLastRow();
512
        short col1 = ap.getLastColumn();
509
        int col1 = ap.getLastColumn();
513
        
510
        
514
        // If the last row is -1, then the
511
        // If the last row is -1, then the
515
        //  reference is for the rest of the column
512
        //  reference is for the rest of the column
Lines 518-541 Link Here
518
        if(row1 == -1 && row0 >= 0) {
515
        if(row1 == -1 && row0 >= 0) {
519
            row1 = (short)sheet.getLastRowNum();
516
            row1 = (short)sheet.getLastRowNum();
520
        }
517
        }
521
        
518
        ValueEval[] values = evalArea(workbook, sheet, row0, col0, row1, col1);
522
        ValueEval[] values = new ValueEval[(row1 - row0 + 1) * (col1 - col0 + 1)];
519
        return new Area2DEval(ap, values);
523
        for (short x = row0; sheet != null && x < row1 + 1; x++) {
524
            HSSFRow row = sheet.getRow(x);
525
            for (short y = col0; row != null && y < col1 + 1; y++) {
526
                values[(x - row0) * (col1 - col0 + 1) + (y - col0)] = 
527
                    getEvalForCell(row.getCell(y), row, sheet, workbook);
528
            }
529
        }
530
        AreaEval ae = new Area2DEval(ap, values);
531
        return ae;
532
    }
520
    }
533
521
534
    public static AreaEval evaluateArea3dPtg(HSSFWorkbook workbook, Area3DPtg a3dp) {
522
    public static AreaEval evaluateArea3dPtg(HSSFWorkbook workbook, Area3DPtg a3dp) {
535
        short row0 = a3dp.getFirstRow();
523
    	int row0 = a3dp.getFirstRow();
536
        short col0 = a3dp.getFirstColumn();
524
    	int col0 = a3dp.getFirstColumn();
537
        short row1 = a3dp.getLastRow();
525
    	int row1 = a3dp.getLastRow();
538
        short col1 = a3dp.getLastColumn();
526
    	int col1 = a3dp.getLastColumn();
539
        Workbook wb = workbook.getWorkbook();
527
        Workbook wb = workbook.getWorkbook();
540
        HSSFSheet xsheet = workbook.getSheetAt(wb.getSheetIndexFromExternSheetIndex(a3dp.getExternSheetIndex()));
528
        HSSFSheet xsheet = workbook.getSheetAt(wb.getSheetIndexFromExternSheetIndex(a3dp.getExternSheetIndex()));
541
        
529
        
Lines 547-565 Link Here
547
            row1 = (short)xsheet.getLastRowNum();
535
            row1 = (short)xsheet.getLastRowNum();
548
        }
536
        }
549
        
537
        
538
        ValueEval[] values = evalArea(workbook, xsheet, row0, col0, row1, col1);
539
        return new Area3DEval(a3dp, values);
540
    }
541
    
542
    private static ValueEval[] evalArea(HSSFWorkbook workbook, HSSFSheet sheet, 
543
    		int row0, int col0, int row1, int col1) {
550
        ValueEval[] values = new ValueEval[(row1 - row0 + 1) * (col1 - col0 + 1)];
544
        ValueEval[] values = new ValueEval[(row1 - row0 + 1) * (col1 - col0 + 1)];
551
        for (short x = row0; xsheet != null && x < row1 + 1; x++) {
545
        for (int x = row0; sheet != null && x < row1 + 1; x++) {
552
            HSSFRow row = xsheet.getRow(x);
546
            HSSFRow row = sheet.getRow(x);
553
            for (short y = col0; row != null && y < col1 + 1; y++) {
547
            for (int y = col0; y < col1 + 1; y++) {
554
                values[(x - row0) * (col1 - col0 + 1) + (y - col0)] = 
548
                ValueEval cellEval;
555
                    getEvalForCell(row.getCell(y), row, xsheet, workbook);
549
                if(row == null) {
550
                	cellEval = BlankEval.INSTANCE;
551
                } else {
552
                	cellEval = getEvalForCell(row.getCell(y), row, sheet, workbook);
553
                }
554
				values[(x - row0) * (col1 - col0 + 1) + (y - col0)] = cellEval;
556
            }
555
            }
557
        }
556
        }
558
        AreaEval ae = new Area3DEval(a3dp, values);
557
        return values;
559
        return ae;
560
    }
558
    }
561
559
562
563
    /**
560
    /**
564
     * returns the OperationEval concrete impl instance corresponding
561
     * returns the OperationEval concrete impl instance corresponding
565
     * to the suplied operationPtg
562
     * to the suplied operationPtg
(-)C:\josh\source\poi\subv\trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area2DEval.java (-23 / +32 lines)
Lines 14-23 Link Here
14
* See the License for the specific language governing permissions and
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
15
* limitations under the License.
16
*/
16
*/
17
/*
17
18
 * Created on May 8, 2005
19
 *
20
 */
21
package org.apache.poi.hssf.record.formula.eval;
18
package org.apache.poi.hssf.record.formula.eval;
22
19
23
import org.apache.poi.hssf.record.formula.AreaPtg;
20
import org.apache.poi.hssf.record.formula.AreaPtg;
Lines 27-74 Link Here
27
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
24
 * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
28
 *   
25
 *   
29
 */
26
 */
30
public class Area2DEval implements AreaEval {
27
public final class Area2DEval implements AreaEval {
28
// TODO -refactor with Area3DEval
29
    private final AreaPtg _delegate;
31
30
32
    private AreaPtg delegate;
31
    private final ValueEval[] _values;
33
32
34
    private ValueEval[] values;
35
36
    public Area2DEval(Ptg ptg, ValueEval[] values) {
33
    public Area2DEval(Ptg ptg, ValueEval[] values) {
37
        this.delegate = (AreaPtg) ptg;
34
        if(ptg == null) {
38
        this.values = values;
35
            throw new IllegalArgumentException("ptg must not be null");
36
        }
37
        if(values == null) {
38
            throw new IllegalArgumentException("values must not be null");
39
        }
40
        for(int i=values.length-1; i>=0; i--) {
41
            if(values[i] == null) {
42
                throw new IllegalArgumentException("value array elements must not be null");
43
            }
44
        }
45
        // TODO - check size of array vs size of AreaPtg
46
        _delegate = (AreaPtg) ptg;
47
        _values = values;
39
    }
48
    }
40
49
41
    public short getFirstColumn() {
50
    public int getFirstColumn() {
42
        return delegate.getFirstColumn();
51
        return _delegate.getFirstColumn();
43
    }
52
    }
44
53
45
    public int getFirstRow() {
54
    public int getFirstRow() {
46
        return delegate.getFirstRow();
55
        return _delegate.getFirstRow();
47
    }
56
    }
48
57
49
    public short getLastColumn() {
58
    public int getLastColumn() {
50
        return delegate.getLastColumn();
59
        return _delegate.getLastColumn();
51
    }
60
    }
52
61
53
    public int getLastRow() {
62
    public int getLastRow() {
54
        return delegate.getLastRow();
63
        return _delegate.getLastRow();
55
    }
64
    }
56
65
57
    public ValueEval[] getValues() {
66
    public ValueEval[] getValues() {
58
        return values;
67
        return _values;
59
    }
68
    }
60
    
69
    
61
    public ValueEval getValueAt(int row, short col) {
70
    public ValueEval getValueAt(int row, int col) {
62
        ValueEval retval;
71
        ValueEval retval;
63
        int index = ((row-getFirstRow())*(getLastColumn()-getFirstColumn()+1))+(col-getFirstColumn());
72
        int index = ((row-getFirstRow())*(getLastColumn()-getFirstColumn()+1))+(col-getFirstColumn());
64
        if (index <0 || index >= values.length)
73
        if (index <0 || index >= _values.length)
65
            retval = ErrorEval.VALUE_INVALID;
74
            retval = ErrorEval.VALUE_INVALID;
66
        else 
75
        else 
67
            retval = values[index];
76
            retval = _values[index];
68
        return retval;
77
        return retval;
69
    }
78
    }
70
    
79
    
71
    public boolean contains(int row, short col) {
80
    public boolean contains(int row, int col) {
72
        return (getFirstRow() <= row) && (getLastRow() >= row) 
81
        return (getFirstRow() <= row) && (getLastRow() >= row) 
73
            && (getFirstColumn() <= col) && (getLastColumn() >= col);
82
            && (getFirstColumn() <= col) && (getLastColumn() >= col);
74
    }
83
    }
Lines 82-91 Link Here
82
    }
91
    }
83
    
92
    
84
    public boolean isColumn() {
93
    public boolean isColumn() {
85
        return delegate.getFirstColumn() == delegate.getLastColumn();
94
        return _delegate.getFirstColumn() == _delegate.getLastColumn();
86
    }
95
    }
87
96
88
    public boolean isRow() {
97
    public boolean isRow() {
89
        return delegate.getFirstRow() == delegate.getLastRow();
98
        return _delegate.getFirstRow() == _delegate.getLastRow();
90
    }
99
    }
91
}
100
}
(-)C:\josh\source\poi\subv\trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Area3DEval.java (-24 / +32 lines)
Lines 14-23 Link Here
14
* See the License for the specific language governing permissions and
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
15
* limitations under the License.
16
*/
16
*/
17
/*
17
18
 * Created on May 8, 2005
19
 *
20
 */
21
package org.apache.poi.hssf.record.formula.eval;
18
package org.apache.poi.hssf.record.formula.eval;
22
19
23
import org.apache.poi.hssf.record.formula.Area3DPtg;
20
import org.apache.poi.hssf.record.formula.Area3DPtg;
Lines 28-74 Link Here
28
 *  
25
 *  
29
 */
26
 */
30
public final class Area3DEval implements AreaEval {
27
public final class Area3DEval implements AreaEval {
28
	// TODO -refactor with Area3DEval
29
    private final Area3DPtg _delegate;
31
30
32
    private Area3DPtg delegate;
31
    private final ValueEval[] _values;
33
32
34
    private ValueEval[] values;
35
36
    public Area3DEval(Ptg ptg, ValueEval[] values) {
33
    public Area3DEval(Ptg ptg, ValueEval[] values) {
37
        this.values = values;
34
        if(ptg == null) {
38
        this.delegate = (Area3DPtg) ptg;
35
            throw new IllegalArgumentException("ptg must not be null");
36
        }
37
        if(values == null) {
38
            throw new IllegalArgumentException("values must not be null");
39
        }
40
        for(int i=values.length-1; i>=0; i--) {
41
            if(values[i] == null) {
42
                throw new IllegalArgumentException("value array elements must not be null");
43
            }
44
        }
45
        // TODO - check size of array vs size of AreaPtg
46
        _values = values;
47
        _delegate = (Area3DPtg) ptg;
39
    }
48
    }
40
49
41
    public short getFirstColumn() {
50
    public int getFirstColumn() {
42
        return delegate.getFirstColumn();
51
        return _delegate.getFirstColumn();
43
    }
52
    }
44
53
45
    public int getFirstRow() {
54
    public int getFirstRow() {
46
        return delegate.getFirstRow();
55
        return _delegate.getFirstRow();
47
    }
56
    }
48
57
49
    public short getLastColumn() {
58
    public int getLastColumn() {
50
        return delegate.getLastColumn();
59
        return (short) _delegate.getLastColumn();
51
    }
60
    }
52
61
53
    public int getLastRow() {
62
    public int getLastRow() {
54
        return delegate.getLastRow();
63
        return _delegate.getLastRow();
55
    }
64
    }
56
65
57
    public ValueEval[] getValues() {
66
    public ValueEval[] getValues() {
58
        return values;
67
        return _values;
59
    }
68
    }
60
    
69
    
61
    public ValueEval getValueAt(int row, short col) {
70
    public ValueEval getValueAt(int row, int col) {
62
        ValueEval retval;
71
        ValueEval retval;
63
        int index = (row-getFirstRow())*(col-getFirstColumn());
72
        int index = (row-getFirstRow())*(col-getFirstColumn());
64
        if (index <0 || index >= values.length)
73
        if (index <0 || index >= _values.length)
65
            retval = ErrorEval.VALUE_INVALID;
74
            retval = ErrorEval.VALUE_INVALID;
66
        else 
75
        else 
67
            retval = values[index];
76
            retval = _values[index];
68
        return retval;
77
        return retval;
69
    }
78
    }
70
    
79
    
71
    public boolean contains(int row, short col) {
80
    public boolean contains(int row, int col) {
72
        return (getFirstRow() <= row) && (getLastRow() >= row) 
81
        return (getFirstRow() <= row) && (getLastRow() >= row) 
73
            && (getFirstColumn() <= col) && (getLastColumn() >= col);
82
            && (getFirstColumn() <= col) && (getLastColumn() >= col);
74
    }
83
    }
Lines 83-97 Link Here
83
    
92
    
84
    
93
    
85
    public boolean isColumn() {
94
    public boolean isColumn() {
86
        return delegate.getFirstColumn() == delegate.getLastColumn();
95
        return _delegate.getFirstColumn() == _delegate.getLastColumn();
87
    }
96
    }
88
97
89
    public boolean isRow() {
98
    public boolean isRow() {
90
        return delegate.getFirstRow() == delegate.getLastRow();
99
        return _delegate.getFirstRow() == _delegate.getLastRow();
91
    }
100
    }
92
101
93
    public int getExternSheetIndex() {
102
    public int getExternSheetIndex() {
94
        return delegate.getExternSheetIndex();
103
        return _delegate.getExternSheetIndex();
95
    }
104
    }
96
97
}
105
}
(-)C:\josh\source\poi\subv\trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref2DEval.java (-2 / +8 lines)
Lines 29-44 Link Here
29
    private final ReferencePtg delegate;
29
    private final ReferencePtg delegate;
30
    
30
    
31
    public Ref2DEval(ReferencePtg ptg, ValueEval ve) {
31
    public Ref2DEval(ReferencePtg ptg, ValueEval ve) {
32
        if(ve == null) {
33
            throw new IllegalArgumentException("ve must not be null");
34
        }
35
        if(false && ptg == null) { // TODO - fix dodgy code in MultiOperandNumericFunction
36
            throw new IllegalArgumentException("ptg must not be null");
37
        }
32
        value = ve;
38
        value = ve;
33
        delegate = ptg;
39
        delegate = ptg;
34
    }
40
    }
35
    public ValueEval getInnerValueEval() {
41
    public ValueEval getInnerValueEval() {
36
        return value;
42
        return value;
37
    }
43
    }
38
    public short getRow() {
44
    public int getRow() {
39
        return delegate.getRow();
45
        return delegate.getRow();
40
    }
46
    }
41
    public short getColumn() {
47
    public int getColumn() {
42
        return delegate.getColumn();
48
        return delegate.getColumn();
43
    }
49
    }
44
}
50
}
(-)C:\josh\source\poi\subv\trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/Ref3DEval.java (-2 / +8 lines)
Lines 29-44 Link Here
29
    private final Ref3DPtg delegate;
29
    private final Ref3DPtg delegate;
30
30
31
    public Ref3DEval(Ref3DPtg ptg, ValueEval ve) {
31
    public Ref3DEval(Ref3DPtg ptg, ValueEval ve) {
32
        if(ve == null) {
33
            throw new IllegalArgumentException("ve must not be null");
34
        }
35
        if(ptg == null) {
36
            throw new IllegalArgumentException("ptg must not be null");
37
        }
32
        value = ve;
38
        value = ve;
33
        delegate = ptg;
39
        delegate = ptg;
34
    }
40
    }
35
    public ValueEval getInnerValueEval() {
41
    public ValueEval getInnerValueEval() {
36
        return value;
42
        return value;
37
    }
43
    }
38
    public short getRow() {
44
    public int getRow() {
39
        return delegate.getRow();
45
        return delegate.getRow();
40
    }
46
    }
41
    public short getColumn() {
47
    public int getColumn() {
42
        return delegate.getColumn();
48
        return delegate.getColumn();
43
    }
49
    }
44
    public int getExternSheetIndex() {
50
    public int getExternSheetIndex() {
(-)C:\josh\source\poi\subv\trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/AreaEval.java (-4 / +4 lines)
Lines 42-54 Link Here
42
     * returns the 0-based index of the first col in
42
     * returns the 0-based index of the first col in
43
     * this area.
43
     * this area.
44
     */
44
     */
45
    public short getFirstColumn();
45
    public int getFirstColumn();
46
46
47
    /**
47
    /**
48
     * returns the 0-based index of the last col in
48
     * returns the 0-based index of the last col in
49
     * this area.
49
     * this area.
50
     */
50
     */
51
    public short getLastColumn();
51
    public int getLastColumn();
52
    
52
    
53
    /**
53
    /**
54
     * returns true if the Area's start and end row indexes
54
     * returns true if the Area's start and end row indexes
Lines 80-86 Link Here
80
     * @param row
80
     * @param row
81
     * @param col
81
     * @param col
82
     */
82
     */
83
    public ValueEval getValueAt(int row, short col);
83
    public ValueEval getValueAt(int row, int col);
84
    
84
    
85
    /**
85
    /**
86
     * returns true if the cell at row and col specified 
86
     * returns true if the cell at row and col specified 
Lines 89-95 Link Here
89
     * @param row
89
     * @param row
90
     * @param col
90
     * @param col
91
     */
91
     */
92
    public boolean contains(int row, short col);
92
    public boolean contains(int row, int col);
93
    
93
    
94
    /**
94
    /**
95
     * returns true if the specified col is in range
95
     * returns true if the specified col is in range
(-)C:\josh\source\poi\subv\trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/RefEval.java (-4 / +4 lines)
Lines 40-51 Link Here
40
    public ValueEval getInnerValueEval();
40
    public ValueEval getInnerValueEval();
41
41
42
    /**
42
    /**
43
     * returns the column index.
43
     * returns the zero based column index.
44
     */
44
     */
45
    public short getColumn();
45
    public int getColumn();
46
46
47
    /**
47
    /**
48
     * returns the row index.
48
     * returns the zero based row index.
49
     */
49
     */
50
    public short getRow();
50
    public int getRow();
51
}
51
}
(-)C:\josh\source\poi\subv\trunk/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/LookupUtils.java (-2 / +2 lines)
Lines 287-294 Link Here
287
			// It doesn't matter if eval is a 2D or 3D ref, because that detail is never asked of AreaEval.
287
			// It doesn't matter if eval is a 2D or 3D ref, because that detail is never asked of AreaEval.
288
			// This code only requires the value array item. 
288
			// This code only requires the value array item. 
289
			// anything would be ok for rowIx and colIx, but may as well get it right.
289
			// anything would be ok for rowIx and colIx, but may as well get it right.
290
			short rowIx = refEval.getRow();
290
			int rowIx = refEval.getRow();
291
			short colIx = refEval.getColumn();
291
			int colIx = refEval.getColumn();
292
			AreaPtg ap = new AreaPtg(rowIx, rowIx, colIx, colIx, false, false, false, false);
292
			AreaPtg ap = new AreaPtg(rowIx, rowIx, colIx, colIx, false, false, false, false);
293
			ValueEval value = refEval.getInnerValueEval();
293
			ValueEval value = refEval.getInnerValueEval();
294
			return new Area2DEval(ap, new ValueEval[] { value, });
294
			return new Area2DEval(ap, new ValueEval[] { value, });
(-)C:\josh\source\poi\subv\trunk/src/scratchpad/testcases/org/apache/poi/hssf/model/TestFormulaParserSP.java (-7 / +34 lines)
Lines 1-4 Link Here
1
2
/* ====================================================================
1
/* ====================================================================
3
   Licensed to the Apache Software Foundation (ASF) under one or more
2
   Licensed to the Apache Software Foundation (ASF) under one or more
4
   contributor license agreements.  See the NOTICE file distributed with
3
   contributor license agreements.  See the NOTICE file distributed with
Lines 15-44 Link Here
15
   See the License for the specific language governing permissions and
14
   See the License for the specific language governing permissions and
16
   limitations under the License.
15
   limitations under the License.
17
==================================================================== */
16
==================================================================== */
18
        
17
19
package org.apache.poi.hssf.model;
18
package org.apache.poi.hssf.model;
20
19
21
import junit.framework.TestCase;
20
import junit.framework.TestCase;
22
21
22
import org.apache.poi.hssf.model.FormulaParser.FormulaParseException;
23
import org.apache.poi.hssf.record.formula.FuncVarPtg;
23
import org.apache.poi.hssf.record.formula.FuncVarPtg;
24
import org.apache.poi.hssf.record.formula.NamePtg;
24
import org.apache.poi.hssf.record.formula.NamePtg;
25
import org.apache.poi.hssf.record.formula.Ptg;
25
import org.apache.poi.hssf.record.formula.Ptg;
26
import org.apache.poi.hssf.usermodel.HSSFCell;
26
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
27
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
27
import org.apache.poi.hssf.usermodel.HSSFName;
28
import org.apache.poi.hssf.usermodel.HSSFName;
29
import org.apache.poi.hssf.usermodel.HSSFRow;
28
import org.apache.poi.hssf.usermodel.HSSFSheet;
30
import org.apache.poi.hssf.usermodel.HSSFSheet;
29
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
31
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
32
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue;
30
33
31
/**
34
/**
32
 * Test the low level formula parser functionality,
35
 * Test the low level formula parser functionality,
33
 *  but using parts which need to use the
36
 *  but using parts which need to use the
34
 *  HSSFFormulaEvaluator, which is in scratchpad 
37
 *  HSSFFormulaEvaluator, which is in scratchpad 
35
 */
38
 */
36
public class TestFormulaParserSP extends TestCase {
39
public final class TestFormulaParserSP extends TestCase {
37
40
38
    public TestFormulaParserSP(String name) {
39
        super(name);
40
    }
41
	
42
	public void testWithNamedRange() throws Exception {
41
	public void testWithNamedRange() throws Exception {
43
		HSSFWorkbook workbook = new HSSFWorkbook();
42
		HSSFWorkbook workbook = new HSSFWorkbook();
44
		FormulaParser fp;
43
		FormulaParser fp;
Lines 80-83 Link Here
80
		assertEquals(FuncVarPtg.class, ptgs[1].getClass());
79
		assertEquals(FuncVarPtg.class, ptgs[1].getClass());
81
	}
80
	}
82
81
82
	public void testEvaluateFormulaWithRowBeyond32768_Bug44539() {
83
		
84
		HSSFWorkbook wb = new HSSFWorkbook();
85
		HSSFSheet sheet = wb.createSheet();
86
		wb.setSheetName(0, "Sheet1");
87
		
88
		HSSFRow row = sheet.createRow(0);
89
		HSSFCell cell = row.createCell((short)0);
90
		cell.setCellFormula("SUM(A32769:A32770)");
91
92
		// put some values in the cells to make the evaluation more interesting
93
		sheet.createRow(32768).createCell((short)0).setCellValue(31);
94
		sheet.createRow(32769).createCell((short)0).setCellValue(11);
95
		
96
		HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
97
		fe.setCurrentRow(row);
98
		CellValue result;
99
		try {
100
			result = fe.evaluate(cell);
101
		} catch (FormulaParseException e) {
102
			if(e.getMessage().equals("Found reference to named range \"A\", but that named range wasn't defined!")) {
103
				fail("Identifed bug 44539");
104
			}
105
			throw new RuntimeException(e);
106
		}
107
		assertEquals(HSSFCell.CELL_TYPE_NUMERIC, result.getCellType());
108
		assertEquals(42.0, result.getNumberValue(), 0.0);
109
	}
83
}
110
}
(-)C:\josh\source\poi\subv\trunk/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (-15 / +22 lines)
Lines 1-4 Link Here
1
2
/* ====================================================================
1
/* ====================================================================
3
   Licensed to the Apache Software Foundation (ASF) under one or more
2
   Licensed to the Apache Software Foundation (ASF) under one or more
4
   contributor license agreements.  See the NOTICE file distributed with
3
   contributor license agreements.  See the NOTICE file distributed with
Lines 21-26 Link Here
21
import junit.framework.AssertionFailedError;
20
import junit.framework.AssertionFailedError;
22
import junit.framework.TestCase;
21
import junit.framework.TestCase;
23
22
23
import org.apache.poi.hssf.model.FormulaParser.FormulaParseException;
24
import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
24
import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
25
import org.apache.poi.hssf.record.formula.AddPtg;
25
import org.apache.poi.hssf.record.formula.AddPtg;
26
import org.apache.poi.hssf.record.formula.AreaPtg;
26
import org.apache.poi.hssf.record.formula.AreaPtg;
Lines 59-76 Link Here
59
 * Some tests are also done in scratchpad, if they need
59
 * Some tests are also done in scratchpad, if they need
60
 *  HSSFFormulaEvaluator, which is there
60
 *  HSSFFormulaEvaluator, which is there
61
 */
61
 */
62
public class TestFormulaParser extends TestCase {
62
public final class TestFormulaParser extends TestCase {
63
63
64
    public TestFormulaParser(String name) {
65
        super(name);
66
    }
67
    public void setUp(){
68
        
69
    }
70
    
71
    public void tearDown() {
72
        
73
    }
74
    /**
64
    /**
75
     * @return parsed token array already confirmed not <code>null</code>
65
     * @return parsed token array already confirmed not <code>null</code>
76
     */
66
     */
Lines 831-840 Link Here
831
        try {
821
        try {
832
            parseFormula(formula);
822
            parseFormula(formula);
833
            throw new AssertionFailedError("expected parse exception");
823
            throw new AssertionFailedError("expected parse exception");
824
        } catch (FormulaParseException e) {
825
            // expected during successful test
826
            assertNotNull(e.getMessage());
834
        } catch (RuntimeException e) {
827
        } catch (RuntimeException e) {
835
            // TODO - catch more specific exception
828
            e.printStackTrace();
836
            // expected during successful test
829
            fail("Wrong exception:" + e.getMessage());
837
            return;
838
        }
830
        }
839
    }
831
    }
832
833
    public void testSetFormulaWithRowBeyond32768_Bug44539() {
834
        
835
        HSSFWorkbook wb = new HSSFWorkbook();
836
        HSSFSheet sheet = wb.createSheet();
837
        wb.setSheetName(0, "Sheet1");
838
        
839
        HSSFRow row = sheet.createRow(0);
840
        HSSFCell cell = row.createCell((short)0);
841
        cell.setCellFormula("SUM(A32769:A32770)");
842
        if("SUM(A-32767:A-32766)".equals(cell.getCellFormula())) {
843
            fail("Identified bug 44539");
844
        }
845
        assertEquals("SUM(A32769:A32770)", cell.getCellFormula());
846
    }
840
}
847
}
(-)C:\josh\source\poi\subv\trunk/src/testcases/org/apache/poi/hssf/record/formula/TestAreaPtg.java (-9 / +5 lines)
Lines 27-41 Link Here
27
 *
27
 *
28
 * @author Dmitriy Kumshayev
28
 * @author Dmitriy Kumshayev
29
 */
29
 */
30
public class TestAreaPtg extends TestCase
30
public final class TestAreaPtg extends TestCase {
31
{
32
31
33
	AreaPtg relative;
32
	AreaPtg relative;
34
	AreaPtg absolute;
33
	AreaPtg absolute;
35
	
34
	
36
	protected void setUp() throws Exception
35
	protected void setUp() {
37
	{
38
		super.setUp();
39
		short firstRow=5;
36
		short firstRow=5;
40
		short lastRow=13;
37
		short lastRow=13;
41
		short firstCol=7;
38
		short firstCol=7;
Lines 64-73 Link Here
64
	}
61
	}
65
62
66
63
67
	public void resetColumns(AreaPtg aptg)
64
	private static void resetColumns(AreaPtg aptg) {
68
	{
65
		int fc = aptg.getFirstColumn();
69
		short fc = aptg.getFirstColumn();
66
		int lc = aptg.getLastColumn();
70
		short lc = aptg.getLastColumn();
71
		aptg.setFirstColumn(fc);
67
		aptg.setFirstColumn(fc);
72
		aptg.setLastColumn(lc);
68
		aptg.setLastColumn(lc);
73
		assertEquals(fc , aptg.getFirstColumn() );
69
		assertEquals(fc , aptg.getFirstColumn() );

Return to bug 44539