2002-04-28 18:22:47 -04:00
|
|
|
/* ====================================================================
|
2004-08-23 04:52:54 -04:00
|
|
|
Copyright 2003-2004 Apache Software Foundation
|
2004-04-09 09:05:39 -04:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
2002-04-28 18:22:47 -04:00
|
|
|
|
|
|
|
package org.apache.poi.hssf.record.formula;
|
|
|
|
|
|
|
|
import org.apache.poi.util.LittleEndian;
|
|
|
|
import org.apache.poi.util.BitField;
|
|
|
|
|
2002-05-04 11:45:05 -04:00
|
|
|
import org.apache.poi.hssf.util.CellReference;
|
2003-08-31 02:16:57 -04:00
|
|
|
import org.apache.poi.hssf.model.Workbook;
|
2005-08-18 03:06:44 -04:00
|
|
|
import org.apache.poi.hssf.record.RecordInputStream;
|
2002-04-28 18:22:47 -04:00
|
|
|
|
|
|
|
/**
|
2002-05-27 17:00:12 -04:00
|
|
|
* ReferencePtg - handles references (such as A1, A2, IA4)
|
2002-04-28 18:22:47 -04:00
|
|
|
* @author Andrew C. Oliver (acoliver@apache.org)
|
2002-09-04 20:26:28 -04:00
|
|
|
* @author Jason Height (jheight at chariot dot net dot au)
|
2002-04-28 18:22:47 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class ReferencePtg extends Ptg
|
|
|
|
{
|
|
|
|
private final static int SIZE = 5;
|
2002-05-27 17:00:12 -04:00
|
|
|
public final static byte sid = 0x24;
|
|
|
|
//public final static byte sid = 0x44;
|
2002-04-28 18:22:47 -04:00
|
|
|
private short field_1_row;
|
|
|
|
private short field_2_col;
|
|
|
|
private BitField rowRelative = new BitField(0x8000);
|
|
|
|
private BitField colRelative = new BitField(0x4000);
|
|
|
|
|
2002-09-04 20:26:28 -04:00
|
|
|
private ReferencePtg() {
|
|
|
|
//Required for clone methods
|
|
|
|
}
|
2002-04-28 18:22:47 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes in a String represnetation of a cell reference and fills out the
|
|
|
|
* numeric fields.
|
|
|
|
*/
|
2002-07-14 20:14:40 -04:00
|
|
|
public ReferencePtg(String cellref) {
|
2002-05-04 11:45:05 -04:00
|
|
|
CellReference c= new CellReference(cellref);
|
|
|
|
setRow((short) c.getRow());
|
|
|
|
setColumn((short) c.getCol());
|
|
|
|
setColRelative(!c.isColAbsolute());
|
|
|
|
setRowRelative(!c.isRowAbsolute());
|
2002-04-28 18:22:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Creates new ValueReferencePtg */
|
|
|
|
|
2005-08-18 03:06:44 -04:00
|
|
|
public ReferencePtg(RecordInputStream in)
|
2002-04-28 18:22:47 -04:00
|
|
|
{
|
2005-08-18 03:06:44 -04:00
|
|
|
field_1_row = in.readShort();
|
|
|
|
field_2_col = in.readShort();
|
2002-04-28 18:22:47 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString()
|
|
|
|
{
|
|
|
|
StringBuffer buffer = new StringBuffer("[ValueReferencePtg]\n");
|
|
|
|
|
|
|
|
buffer.append("row = ").append(getRow()).append("\n");
|
|
|
|
buffer.append("col = ").append(getColumnRaw()).append("\n");
|
|
|
|
buffer.append("rowrelative = ").append(isRowRelative()).append("\n");
|
|
|
|
buffer.append("colrelative = ").append(isColRelative()).append("\n");
|
|
|
|
return buffer.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeBytes(byte [] array, int offset)
|
|
|
|
{
|
2002-05-27 17:00:12 -04:00
|
|
|
array[offset] = (byte) (sid + ptgClass);
|
2002-04-28 18:22:47 -04:00
|
|
|
LittleEndian.putShort(array,offset+1,field_1_row);
|
|
|
|
LittleEndian.putShort(array,offset+3,field_2_col);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRow(short row)
|
|
|
|
{
|
|
|
|
field_1_row = row;
|
|
|
|
}
|
|
|
|
|
|
|
|
public short getRow()
|
|
|
|
{
|
|
|
|
return field_1_row;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isRowRelative()
|
|
|
|
{
|
|
|
|
return rowRelative.isSet(field_2_col);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRowRelative(boolean rel) {
|
|
|
|
field_2_col=rowRelative.setShortBoolean(field_2_col,rel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isColRelative()
|
|
|
|
{
|
|
|
|
return colRelative.isSet(field_2_col);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setColRelative(boolean rel) {
|
|
|
|
field_2_col=colRelative.setShortBoolean(field_2_col,rel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setColumnRaw(short col)
|
|
|
|
{
|
|
|
|
field_2_col = col;
|
|
|
|
}
|
|
|
|
|
|
|
|
public short getColumnRaw()
|
|
|
|
{
|
|
|
|
return field_2_col;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setColumn(short col)
|
|
|
|
{
|
|
|
|
field_2_col = col; // fix this
|
|
|
|
}
|
|
|
|
|
|
|
|
public short getColumn()
|
|
|
|
{
|
|
|
|
return rowRelative.setShortBoolean(colRelative.setShortBoolean(field_2_col,false),false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getSize()
|
|
|
|
{
|
|
|
|
return SIZE;
|
|
|
|
}
|
|
|
|
|
2003-08-31 02:16:57 -04:00
|
|
|
public String toFormulaString(Workbook book)
|
2002-04-28 18:22:47 -04:00
|
|
|
{
|
2002-05-04 11:45:05 -04:00
|
|
|
//TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
|
|
|
|
return (new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).toString();
|
2002-04-28 18:22:47 -04:00
|
|
|
}
|
2002-05-27 17:00:12 -04:00
|
|
|
|
|
|
|
public byte getDefaultOperandClass() {
|
|
|
|
return Ptg.CLASS_REF;
|
|
|
|
}
|
|
|
|
|
2002-09-04 20:26:28 -04:00
|
|
|
public Object clone() {
|
|
|
|
ReferencePtg ptg = new ReferencePtg();
|
|
|
|
ptg.field_1_row = field_1_row;
|
|
|
|
ptg.field_2_col = field_2_col;
|
2003-07-27 14:49:52 -04:00
|
|
|
ptg.setClass(ptgClass);
|
2002-09-04 20:26:28 -04:00
|
|
|
return ptg;
|
|
|
|
}
|
2002-04-28 18:22:47 -04:00
|
|
|
}
|