got SUM working and some debug stuff.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352563 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew C. Oliver 2002-04-30 01:05:49 +00:00
parent b8802bb429
commit 453fe100c5
5 changed files with 104 additions and 7 deletions

View File

@ -534,8 +534,9 @@ public class FormulaRecord
for (int k = 0; k < field_8_parsed_expr.size(); k++ ) { for (int k = 0; k < field_8_parsed_expr.size(); k++ ) {
buffer.append("formula ").append(k).append(" ") /* buffer.append("formula ").append(k).append(" ")
.append(((Ptg)field_8_parsed_expr.get(k)).toFormulaString()); .append(((Ptg)field_8_parsed_expr.get(k)).toFormulaString());*/
((Ptg)field_8_parsed_expr.get(k)).toDebugString();
} }

View File

@ -138,6 +138,10 @@ public class AttrPtg
{ {
return sum.isSet(getOptions()); return sum.isSet(getOptions());
} }
public void setSum(boolean bsum) {
field_1_options=sum.setByteBoolean(field_1_options,bsum);
}
// lets hope no one uses this anymore // lets hope no one uses this anymore
public boolean isBaxcel() public boolean isBaxcel()
@ -180,6 +184,9 @@ public class AttrPtg
public void writeBytes(byte [] array, int offset) public void writeBytes(byte [] array, int offset)
{ {
array[offset]=sid;
array[offset+1]=field_1_options;
LittleEndian.putShort(array,offset+2,field_2_data);
} }
public int getSize() public int getSize()
@ -206,10 +213,7 @@ public class AttrPtg
{ {
return -1; return -1;
} }
public void manipulate(List source, List results, int pos) {
}
public String toFormulaString(String[] operands) { public String toFormulaString(String[] operands) {
return "SUM(" + operands[ 0 ] + ")"; return "SUM(" + operands[ 0 ] + ")";
} }

View File

@ -244,7 +244,7 @@ public class FormulaParser {
int numArgs = Arguments(); int numArgs = Arguments();
Match(')'); Match(')');
//this is the end of the function //this is the end of the function
tokens.add(new FunctionPtg(name,(byte)numArgs)); tokens.add(function(name,(byte)numArgs));
} else if (Look == ':') { // this is a AreaReference } else if (Look == ':') { // this is a AreaReference
String first = name; String first = name;
Match(':'); Match(':');
@ -261,6 +261,19 @@ public class FormulaParser {
} }
} }
private Ptg function(String name,byte numArgs) {
Ptg retval = null;
if (numArgs == 1 && name.equals("SUM")) {
AttrPtg ptg = new AttrPtg();
ptg.setData((short)1); //sums don't care but this is what excel does.
ptg.setSum(true);
retval = ptg;
}
return retval;
}
/** get arguments to a function */ /** get arguments to a function */
private int Arguments() { private int Arguments() {
int numArgs = 0; int numArgs = 0;

View File

@ -296,5 +296,19 @@ public abstract class Ptg
return 0; return 0;
} }
/**
* dump a debug representation (hexdump) to a strnig
*/
public void toDebugString() {
byte[] ba = new byte[getSize()];
String retval=null;
writeBytes(ba,0);
try {
retval = org.apache.poi.util.HexDump.dump(ba,0,0);
} catch (Exception e) {
e.printStackTrace();
}
}
} }

View File

@ -148,6 +148,71 @@ public class HexDump
} }
} }
/**
* dump an array of bytes to a String
*
* @param data the byte array to be dumped
* @param offset its offset, whatever that might mean
* @param index initial index into the byte array
*
* @exception IOException is thrown if anything goes wrong writing
* the data to stream
* @exception ArrayIndexOutOfBoundsException if the index is
* outside the data array's bounds
* @return output string
*/
public static String dump(final byte [] data, final long offset,
final int index) {
StringBuffer buffer;
if ((index < 0) || (index >= data.length))
{
throw new ArrayIndexOutOfBoundsException(
"illegal index: " + index + " into array of length "
+ data.length);
}
long display_offset = offset + index;
buffer = new StringBuffer(74);
for (int j = index; j < data.length; j += 16)
{
int chars_read = data.length - j;
if (chars_read > 16)
{
chars_read = 16;
}
buffer.append(dump(display_offset)).append(' ');
for (int k = 0; k < 16; k++)
{
if (k < chars_read)
{
buffer.append(dump(data[ k + j ]));
}
else
{
buffer.append(" ");
}
buffer.append(' ');
}
for (int k = 0; k < chars_read; k++)
{
if ((data[ k + j ] >= ' ') && (data[ k + j ] < 127))
{
buffer.append(( char ) data[ k + j ]);
}
else
{
buffer.append('.');
}
}
buffer.append(EOL);
display_offset += chars_read;
}
return buffer.toString();
}
public static final String EOL = public static final String EOL =
System.getProperty("line.separator"); System.getProperty("line.separator");
private static final StringBuffer _lbuffer = new StringBuffer(8); private static final StringBuffer _lbuffer = new StringBuffer(8);