Holy schisse - cell referenecs seem to be working at least for simple formulas

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352535 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew C. Oliver 2002-04-28 18:45:10 +00:00
parent ab97dacce6
commit a3fc345121
2 changed files with 41 additions and 11 deletions

View File

@ -68,7 +68,6 @@ import java.io.File;
/**
* EXPERIMENTAL
*
* @author Avik Sengupta <avik AT Avik Sengupta DOT com>
*
* This class parses a formula string into a List of tokens in RPN order
* Inspired by
@ -77,6 +76,9 @@ import java.io.File;
* <expression> ::= <term> [<addop> <term>]*
* <term> ::= <factor> [ <mulop> <factor ]*
* <factor> ::= <number> | (<expression>) | <cellRef>
*
* @author Avik Sengupta <avik AT Avik Sengupta DOT com>
* @author Andrew C. oliver (acoliver at apache dot org)
*/
public class FormulaParser {
@ -234,21 +236,21 @@ public class FormulaParser {
/** Parse and Translate a Identifier */
private void Ident() {
String Name;
Name = GetName();
String name;
name = GetName();
if (Look == '('){
//This is a function
Match('(');
int numArgs = Arguments();
Match(')');
//this is the end of the function
tokens.add(new DummyFunctionPtg(Name,numArgs));
tokens.add(new DummyFunctionPtg(name,numArgs));
} else {
//this can be either a cell ref or a named range !!
boolean cellRef = true ; //we should probably do it with reg exp??
if (cellRef) {
tokens.add(new ValueReferencePtg()); //TODO we need to pass in Name somewhere??
tokens.add(new ValueReferencePtg(name)); //TODO we need to pass in Name somewhere??
}else {
//handle after named range is integrated!!
}

View File

@ -63,9 +63,14 @@ package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.util.ReferenceUtil;
/**
*
* @author andy
* ValueReferencePtg - handles references (such as A1, A2, IA4) - Should also
* be made to handle relative versus absolute references but I don't know enough
* about using them in excel to know if its correct. Seems inverted to me.
* FIXME = correct abs vs relative references
* @author Andrew C. Oliver (acoliver@apache.org)
*/
public class ValueReferencePtg
@ -83,6 +88,18 @@ public class ValueReferencePtg
public ValueReferencePtg()
{
}
/**
* Takes in a String represnetation of a cell reference and fills out the
* numeric fields.
*/
public ValueReferencePtg(String cellref) {
int[] xy = ReferenceUtil.getXYFromReference(cellref);
setRow((short)xy[0]);
setColumn((short)xy[1]);
setColRelative(true);
setRowRelative(true);
}
/** Creates new ValueReferencePtg */
@ -107,6 +124,9 @@ public class ValueReferencePtg
public void writeBytes(byte [] array, int offset)
{
array[offset] = sid;
LittleEndian.putShort(array,offset+1,field_1_row);
LittleEndian.putShort(array,offset+3,field_2_col);
}
public void setRow(short row)
@ -123,10 +143,18 @@ public class ValueReferencePtg
{
return rowRelative.isSet(field_2_col);
}
public void setRowRelative(boolean rel) {
field_2_col=rowRelative.setShortBoolean(field_2_col,rel);
}
public boolean isColRelative()
{
return rowRelative.isSet(field_2_col);
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)
@ -146,7 +174,7 @@ public class ValueReferencePtg
public short getColumn()
{
return field_2_col; // fix this
return rowRelative.setShortBoolean(colRelative.setShortBoolean(field_2_col,false),false);
}
public int getSize()
@ -156,6 +184,6 @@ public class ValueReferencePtg
public String toFormulaString()
{
return "NO IDEA YET VALUE REF";
return ReferenceUtil.getReferenceFromXY(getRow(),getColumn());
}
}