deleted DummyFunctionPtg and renamed it to FunctionPtg (fixing to implement)

Added Range creation to FormulaParser (sorry to steal all teh fun Avik, just i want to get this flying!)
Made area ptg work.  Boy that was some crappy stuff I did back in Oct/November for
prelim formula stuff.  What the heck was I thinking.  Yuck!


git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352548 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew C. Oliver 2002-04-28 23:43:35 +00:00
parent 7bd031a16b
commit 91df898367
3 changed files with 64 additions and 50 deletions

View File

@ -61,6 +61,9 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.util.ReferenceUtil;
/** /**
* Specifies a rectangular area of cells * Specifies a rectangular area of cells
@ -77,12 +80,26 @@ public class AreaPtg
private short field_3_first_column; private short field_3_first_column;
private short field_4_last_column; private short field_4_last_column;
private BitField rowRelative = new BitField(0x8000);
private BitField colRelative = new BitField(0x4000);
private BitField column = new BitField(0x3FFF);
/** Creates new AreaPtg */ /** Creates new AreaPtg */
public AreaPtg() public AreaPtg()
{ {
} }
public AreaPtg(String arearef) {
int[] xyxy = ReferenceUtil.getXYXYFromAreaRef(arearef);
setFirstRow((short)xyxy[0]);
setFirstColumn((short)xyxy[1]);
setLastRow((short)xyxy[2]);
setLastColumn((short)xyxy[3]);
}
public AreaPtg(byte [] data, int offset) public AreaPtg(byte [] data, int offset)
{ {
offset++; offset++;
@ -103,16 +120,20 @@ public class AreaPtg
buffer.append("firstCol = " + getFirstColumn()).append("\n"); buffer.append("firstCol = " + getFirstColumn()).append("\n");
buffer.append("lastCol = " + getLastColumn()).append("\n"); buffer.append("lastCol = " + getLastColumn()).append("\n");
buffer.append("firstColRowRel= " buffer.append("firstColRowRel= "
+ isFirstColRowRelative()).append("\n"); + isFirstRowRelative()).append("\n");
buffer.append("lastColRowRel = " buffer.append("lastColRowRel = "
+ isLastColRowRelative()).append("\n"); + isLastRowRelative()).append("\n");
buffer.append("firstColRel = " + isFirstColRelative()).append("\n"); buffer.append("firstColRel = " + isFirstColRelative()).append("\n");
buffer.append("lastColRel = " + isLastColRelative()).append("\n"); buffer.append("lastColRel = " + isLastColRelative()).append("\n");
return buffer.toString(); return buffer.toString();
} }
public void writeBytes(byte [] array, int offset) public void writeBytes(byte [] array, int offset) {
{ array[offset] = sid;
LittleEndian.putShort(array,offset+1,field_1_first_row);
LittleEndian.putShort(array,offset+3,field_2_last_row);
LittleEndian.putShort(array,offset+5,field_3_first_column);
LittleEndian.putShort(array,offset+7,field_4_last_column);
} }
public int getSize() public int getSize()
@ -142,7 +163,7 @@ public class AreaPtg
public short getFirstColumn() public short getFirstColumn()
{ {
return ( short ) (field_3_first_column & 0x3FFF); return column.getShortValue(field_3_first_column);
} }
public short getFirstColumnRaw() public short getFirstColumnRaw()
@ -150,16 +171,25 @@ public class AreaPtg
return field_3_first_column; return field_3_first_column;
} }
public boolean isFirstColRowRelative() public boolean isFirstRowRelative()
{ {
return (((getFirstColumnRaw()) & 0x8000) == 0x8000); return rowRelative.isSet(field_3_first_column);
}
public void setFirstRowRelative(boolean rel) {
field_3_first_column=rowRelative.setShortBoolean(field_3_first_column,rel);
} }
public boolean isFirstColRelative() public boolean isFirstColRelative()
{ {
return (((getFirstColumnRaw()) & 0x4000) == 0x4000); return colRelative.isSet(field_3_first_column);
} }
public void setFirstColRelative(boolean rel) {
field_3_first_column=colRelative.setShortBoolean(field_3_first_column,rel);
}
public void setFirstColumn(short column) public void setFirstColumn(short column)
{ {
field_3_first_column = column; // fixme field_3_first_column = column; // fixme
@ -172,7 +202,7 @@ public class AreaPtg
public short getLastColumn() public short getLastColumn()
{ {
return ( short ) (field_4_last_column & 0x3FFF); // fixme return column.getShortValue(field_4_last_column);
} }
public short getLastColumnRaw() public short getLastColumnRaw()
@ -180,16 +210,25 @@ public class AreaPtg
return field_4_last_column; return field_4_last_column;
} }
public boolean isLastColRowRelative() public boolean isLastRowRelative()
{ {
return (((getLastColumnRaw()) & 0x8000) == 1); return rowRelative.isSet(field_4_last_column);
}
public void setLastRowRelative(boolean rel) {
field_4_last_column=rowRelative.setShortBoolean(field_4_last_column,rel);
} }
public boolean isLastColRelative() public boolean isLastColRelative()
{ {
return (((getFirstColumnRaw()) & 0x4000) == 1); return colRelative.isSet(field_4_last_column);
} }
public void setLastColRelative(boolean rel) {
field_4_last_column=colRelative.setShortBoolean(field_4_last_column,rel);
}
public void setLastColumn(short column) public void setLastColumn(short column)
{ {
field_4_last_column = column; // fixme field_4_last_column = column; // fixme
@ -204,41 +243,10 @@ public class AreaPtg
{ {
String firstrow = "" + (getFirstRow() + 1); String firstrow = "" + (getFirstRow() + 1);
String lastrow = null; String lastrow = null;
if (isLastColRowRelative())
{
lastrow = "" + (getFirstRow() + getLastRow());
}
else
{
lastrow = "" + (getLastRow() + 1);
}
// String firstcol = ""+ // String firstcol = ""+
// String lastcol // String lastcol
return colNumToLetter(getFirstColumn()) + firstrow + ":" return ReferenceUtil.getReferenceFromXY(getFirstRow(),getFirstColumn()) + ":"
+ colNumToLetter(getLastColumn()) + lastrow; + ReferenceUtil.getReferenceFromXY(getLastRow(),getLastColumn());
} }
public String colNumToLetter(int col)
{
byte[] b =
{
0x41
};
b[ 0 ] += ( byte ) col;
String retval = null;
try
{
retval = new String(b, "UTF-8");
}
catch (java.io.UnsupportedEncodingException e)
{
throw new RuntimeException(
"NON JDK 1.3 COMPLIANT JVM -- YOUR JVM MUST SUPPORT UTF-8 encoding as per docs!");
}
return retval;
}
} }

View File

@ -245,6 +245,12 @@ public class FormulaParser {
Match(')'); Match(')');
//this is the end of the function //this is the end of the function
tokens.add(new DummyFunctionPtg(name,numArgs)); tokens.add(new DummyFunctionPtg(name,numArgs));
} else if (Look == ':') { // this is a AreaReference
String first = name;
GetChar();
String second = GetName();
tokens.add(new AreaPtg(first+":"+second));
//String second = ;
} else { } else {
//this can be either a cell ref or a named range !! //this can be either a cell ref or a named range !!
@ -383,7 +389,7 @@ end;
/** Initialize */ /** Initialize */
private void Init() { private void init() {
GetChar(); GetChar();
SkipWhite(); SkipWhite();
} }
@ -393,7 +399,7 @@ end;
*/ */
public void parse() { public void parse() {
synchronized (tokens) { synchronized (tokens) {
Init(); init();
Expression(); Expression();
} }
} }

View File

@ -15,14 +15,14 @@ import java.util.List;
* @author aviks * @author aviks
* @version * @version
*/ */
public class DummyFunctionPtg extends OperationPtg { public class FunctionPtg extends OperationPtg {
private String name; private String name;
private int numOperands; private int numOperands;
/** Creates new DummyFunctionPtg */ /** Creates new DummyFunctionPtg */
public DummyFunctionPtg() { public FunctionPtg() {
} }
public DummyFunctionPtg(String pName,int pNumOperands) { public FunctionPtg(String pName, int pNumOperands) {
name=pName; name=pName;
numOperands = pNumOperands; numOperands = pNumOperands;
} }