acoliver    02/04/29 18:05:49

  Modified:    src/java/org/apache/poi/hssf/record/formula AttrPtg.java
                        FormulaParser.java Ptg.java
               src/java/org/apache/poi/hssf/record FormulaRecord.java
               src/java/org/apache/poi/util HexDump.java
  Log:
  got SUM working and some debug stuff.
  
  Revision  Changes    Path
  1.4       +8 -4      
jakarta-poi/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java
  
  Index: AttrPtg.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/AttrPtg.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AttrPtg.java      27 Apr 2002 14:07:53 -0000      1.3
  +++ AttrPtg.java      30 Apr 2002 01:05:48 -0000      1.4
  @@ -138,6 +138,10 @@
       {
           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 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 @@
       {
           return -1;
       }
  -    
  -    public void manipulate(List source, List results, int pos) {
  -    }
  -    
  +        
       public String toFormulaString(String[] operands) {
           return "SUM(" + operands[ 0 ] + ")";
       }    
  
  
  
  1.12      +14 -1     
jakarta-poi/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java
  
  Index: FormulaParser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/FormulaParser.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- FormulaParser.java        30 Apr 2002 00:19:49 -0000      1.11
  +++ FormulaParser.java        30 Apr 2002 01:05:48 -0000      1.12
  @@ -244,7 +244,7 @@
               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(':');
  @@ -259,6 +259,19 @@
                   //handle after named range is integrated!!
               }
           }
  +    }
  +    
  +    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 */
  
  
  
  1.12      +14 -0     jakarta-poi/src/java/org/apache/poi/hssf/record/formula/Ptg.java
  
  Index: Ptg.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/Ptg.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Ptg.java  30 Apr 2002 00:18:29 -0000      1.11
  +++ Ptg.java  30 Apr 2002 01:05:48 -0000      1.12
  @@ -296,5 +296,19 @@
           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();
  +        }
  +    }
  +    
       
   }
  
  
  
  1.10      +3 -2      
jakarta-poi/src/java/org/apache/poi/hssf/record/FormulaRecord.java
  
  Index: FormulaRecord.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/FormulaRecord.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FormulaRecord.java        29 Apr 2002 01:25:28 -0000      1.9
  +++ FormulaRecord.java        30 Apr 2002 01:05:49 -0000      1.10
  @@ -534,8 +534,9 @@
               
               
               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();
               }
               
               
  
  
  
  1.4       +65 -0     jakarta-poi/src/java/org/apache/poi/util/HexDump.java
  
  Index: HexDump.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/util/HexDump.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HexDump.java      19 Apr 2002 22:30:50 -0000      1.3
  +++ HexDump.java      30 Apr 2002 01:05:49 -0000      1.4
  @@ -148,6 +148,71 @@
           }
       }
   
  +    /**
  +     * 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);
  
  
  


Reply via email to