git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352563 13f79535-47bb-0310-9956-ffa450edef68tags/REL_1_10
@@ -534,8 +534,9 @@ public class FormulaRecord | |||
for (int k = 0; k < field_8_parsed_expr.size(); k++ ) { | |||
buffer.append("formula ").append(k).append(" ") | |||
.append(((Ptg)field_8_parsed_expr.get(k)).toFormulaString()); | |||
/* buffer.append("formula ").append(k).append(" ") | |||
.append(((Ptg)field_8_parsed_expr.get(k)).toFormulaString());*/ | |||
((Ptg)field_8_parsed_expr.get(k)).toDebugString(); | |||
} | |||
@@ -138,6 +138,10 @@ public class AttrPtg | |||
{ | |||
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 | |||
public boolean isBaxcel() | |||
@@ -180,6 +184,9 @@ public class AttrPtg | |||
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() | |||
@@ -206,10 +213,7 @@ public class AttrPtg | |||
{ | |||
return -1; | |||
} | |||
public void manipulate(List source, List results, int pos) { | |||
} | |||
public String toFormulaString(String[] operands) { | |||
return "SUM(" + operands[ 0 ] + ")"; | |||
} |
@@ -244,7 +244,7 @@ public class FormulaParser { | |||
int numArgs = Arguments(); | |||
Match(')'); | |||
//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 | |||
String first = name; | |||
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 */ | |||
private int Arguments() { | |||
int numArgs = 0; |
@@ -296,5 +296,19 @@ public abstract class Ptg | |||
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(); | |||
} | |||
} | |||
} |
@@ -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 = | |||
System.getProperty("line.separator"); | |||
private static final StringBuffer _lbuffer = new StringBuffer(8); |