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:
parent
ab97dacce6
commit
a3fc345121
@ -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!!
|
||||
}
|
||||
|
@ -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
|
||||
@ -84,6 +89,18 @@ public class 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 */
|
||||
|
||||
public ValueReferencePtg(byte [] data, int offset)
|
||||
@ -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)
|
||||
@ -124,9 +144,17 @@ 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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user