poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject svn commit: r634936 [3/8] - in /poi/branches/ooxml: ./ legal/ src/contrib/src/org/apache/poi/hssf/contrib/view/ src/documentation/content/xdocs/ src/documentation/content/xdocs/getinvolved/ src/documentation/content/xdocs/hslf/ src/java/org/apache/poi/...
Date Sat, 08 Mar 2008 11:49:17 GMT
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/SupBookRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/SupBookRecord.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/SupBookRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/SupBookRecord.java Sat Mar  8 03:49:00 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,72 +14,159 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
+import org.apache.poi.hssf.record.UnicodeString.UnicodeRecordStats;
 import org.apache.poi.util.LittleEndian;
 
 /**
- * Title:        Sup Book  <P>
- * Description:  A Extrenal Workbook Deciption (Sup Book)
+ * Title:        Sup Book (EXTERNALBOOK) <P>
+ * Description:  A External Workbook Description (Suplemental Book)
  *               Its only a dummy record for making new ExternSheet Record <P>
- * REFERENCE:  <P>
+ * REFERENCE:  5.38<P>
  * @author Libin Roman (Vista Portal LDT. Developer)
  * @author Andrew C. Oliver (acoliver@apache.org)
  *
  */
-public class SupBookRecord extends Record
-{
+public final class SupBookRecord extends Record {
+
     public final static short sid = 0x1AE;
-    private short             field_1_number_of_sheets;
-    private short             field_2_flag;
 
+    private static final short SMALL_RECORD_SIZE = 4;
+    private static final short TAG_INTERNAL_REFERENCES = 0x0401;
+    private static final short TAG_ADD_IN_FUNCTIONS = 0x3A01;
 
-    public SupBookRecord()
-    {
-        setFlag((short)0x401);
+    private short             field_1_number_of_sheets;
+    private UnicodeString     field_2_encoded_url;
+    private UnicodeString[]   field_3_sheet_names;
+    private boolean           _isAddInFunctions;
+
+    
+    public static SupBookRecord createInternalReferences(short numberOfSheets) {
+        return new SupBookRecord(false, numberOfSheets);
+    }
+    public static SupBookRecord createAddInFunctions() {
+        return new SupBookRecord(true, (short)0);
+    }
+    public static SupBookRecord createExternalReferences(UnicodeString url, UnicodeString[] sheetNames) {
+        return new SupBookRecord(url, sheetNames);
+    }
+    private SupBookRecord(boolean isAddInFuncs, short numberOfSheets) {
+        // else not 'External References'
+        field_1_number_of_sheets = numberOfSheets;
+        field_2_encoded_url = null;
+        field_3_sheet_names = null;
+        _isAddInFunctions = isAddInFuncs;
+    }
+    public SupBookRecord(UnicodeString url, UnicodeString[] sheetNames) {
+        field_1_number_of_sheets = (short) sheetNames.length;
+        field_2_encoded_url = url;
+        field_3_sheet_names = sheetNames;
+        _isAddInFunctions = false;
     }
 
     /**
      * Constructs a Extern Sheet record and sets its fields appropriately.
      *
-     * @param in the RecordInputstream to read the record from
+     * @param id     id must be 0x16 or an exception will be throw upon validation
+     * @param size  the size of the data area of the record
+     * @param data  data of the record (should not contain sid/len)
      */
-    public SupBookRecord(RecordInputStream in)
-    {
+    public SupBookRecord(RecordInputStream in) {
         super(in);
     }
 
-    protected void validateSid(short id)
-    {
-        if (id != sid)
-        {
-            throw new RecordFormatException("NOT An Supbook RECORD");
+    protected void validateSid(short id) {
+        if (id != sid) {
+            throw new RecordFormatException("NOT An ExternSheet RECORD");
         }
     }
 
+    public boolean isExternalReferences() {
+        return field_3_sheet_names != null;
+    }
+    public boolean isInternalReferences() {
+        return field_3_sheet_names == null && !_isAddInFunctions;
+    }
+    public boolean isAddInFunctions() {
+        return field_3_sheet_names == null && _isAddInFunctions;
+    }
     /**
-     * @param in the RecordInputstream to read the record from
+     * called by the constructor, should set class level fields.  Should throw
+     * runtime exception for bad/incomplete data.
+     *
+     * @param data raw data
+     * @param size size of data
+     * @param offset of the record's data (provided a big array of the file)
      */
-    protected void fillFields(RecordInputStream in)
-    {
-        //For now We use it only for one case
-        //When we need to add an named range when no named ranges was
-        //before it
+    protected void fillFields(RecordInputStream in) {
         field_1_number_of_sheets = in.readShort();
-        field_2_flag = in.readShort();
-    }
-
+        
+        if(in.getLength() > SMALL_RECORD_SIZE) {
+            // 5.38.1 External References
+            _isAddInFunctions = false;
+
+            field_2_encoded_url = in.readUnicodeString();
+            UnicodeString[] sheetNames = new UnicodeString[field_1_number_of_sheets];
+            for (int i = 0; i < sheetNames.length; i++) {
+                sheetNames[i] = in.readUnicodeString();
+            }
+            field_3_sheet_names = sheetNames;
+            return;
+        }
+        // else not 'External References'
+        field_2_encoded_url = null;
+        field_3_sheet_names = null;
+      
+        short nextShort = in.readShort();
+        if(nextShort == TAG_INTERNAL_REFERENCES) {
+            // 5.38.2 'Internal References'
+            _isAddInFunctions = false;
+        } else if(nextShort == TAG_ADD_IN_FUNCTIONS) {
+            // 5.38.3 'Add-In Functions'
+            _isAddInFunctions = true;
+            if(field_1_number_of_sheets != 1) {
+                throw new RuntimeException("Expected 0x0001 for number of sheets field in 'Add-In Functions' but got ("
+                     + field_1_number_of_sheets + ")");
+            }
+        } else {
+            throw new RuntimeException("invalid EXTERNALBOOK code (" 
+                     + Integer.toHexString(nextShort) + ")");
+        }
+     }
 
-    public String toString()
-    {
-        StringBuffer buffer = new StringBuffer();
-        buffer.append("[SUPBOOK]\n");
-        buffer.append("numberosheets = ").append(getNumberOfSheets()).append('\n');
-        buffer.append("flag          = ").append(getFlag()).append('\n');
-        buffer.append("[/SUPBOOK]\n");
-        return buffer.toString();
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        sb.append(getClass().getName()).append(" [SUPBOOK ");
+        
+        if(isExternalReferences()) {
+            sb.append("External References");
+            sb.append(" nSheets=").append(field_1_number_of_sheets);
+            sb.append(" url=").append(field_2_encoded_url);
+        } else if(_isAddInFunctions) {
+            sb.append("Add-In Functions");
+        } else {
+            sb.append("Internal References ");
+            sb.append(" nSheets= ").append(field_1_number_of_sheets);
+        }
+        return sb.toString();
+    }
+    private int getDataSize() {
+        if(!isExternalReferences()) {
+            return SMALL_RECORD_SIZE;
+        }
+        int sum = 2; // u16 number of sheets
+        UnicodeRecordStats urs = new UnicodeRecordStats();
+        field_2_encoded_url.getRecordSize(urs);
+        sum += urs.recordSize;
+        
+        for(int i=0; i<field_3_sheet_names.length; i++) {
+            urs = new UnicodeRecordStats();
+            field_3_sheet_names[i].getRecordSize(urs);
+            sum += urs.recordSize;
+        }
+        return sum;
     }
 
     /**
@@ -92,14 +178,30 @@
      * @param data byte array containing instance data
      * @return number of bytes written
      */
-    public int serialize(int offset, byte [] data)
-    {
+    public int serialize(int offset, byte [] data) {
         LittleEndian.putShort(data, 0 + offset, sid);
-        LittleEndian.putShort(data, 2 + offset, (short) 4);
+        int dataSize = getDataSize();
+        LittleEndian.putShort(data, 2 + offset, (short) dataSize);
         LittleEndian.putShort(data, 4 + offset, field_1_number_of_sheets);
-        LittleEndian.putShort(data, 6 + offset, field_2_flag);
-
-        return getRecordSize();
+               
+        if(isExternalReferences()) {
+            
+            int currentOffset = 6 + offset;
+            UnicodeRecordStats urs = new UnicodeRecordStats();
+            field_2_encoded_url.serialize(urs, currentOffset, data);
+            currentOffset += urs.recordSize;
+            
+            for(int i=0; i<field_3_sheet_names.length; i++) {
+                urs = new UnicodeRecordStats();
+                field_3_sheet_names[i].serialize(urs, currentOffset, data);
+                currentOffset += urs.recordSize;
+            }
+        } else {
+            short field2val = _isAddInFunctions ? TAG_ADD_IN_FUNCTIONS : TAG_INTERNAL_REFERENCES;
+            
+            LittleEndian.putShort(data, 6 + offset, field2val);
+        }
+        return dataSize + 4;
     }
 
     public void setNumberOfSheets(short number){
@@ -110,21 +212,18 @@
         return field_1_number_of_sheets;
     }
 
-    public void setFlag(short flag){
-        field_2_flag = flag;
-    }
-
-    public short getFlag() {
-        return field_2_flag;
-    }
-
-    public int getRecordSize()
-    {
-        return 4 + 4;
+    public int getRecordSize() {
+        return getDataSize() + 4;
     }
 
     public short getSid()
     {
         return sid;
+    }
+    public UnicodeString getURL() {
+        return field_2_encoded_url;
+    }
+    public UnicodeString[] getSheetNames() {
+        return (UnicodeString[]) field_3_sheet_names.clone();
     }
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java Sat Mar  8 03:49:00 2008
@@ -34,7 +34,7 @@
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 
-public class ValueRecordsAggregate
+public final class ValueRecordsAggregate
     extends Record
 {
     public final static short sid       = -1000;
@@ -127,7 +127,7 @@
 
         FormulaRecordAggregate lastFormulaAggregate = null;
         
-        // First up, locate all the shared formulas
+        // First up, locate all the shared formulas for this sheet
         List sharedFormulas = new java.util.ArrayList();
         for (k = offset; k < records.size(); k++)
         {
@@ -135,6 +135,10 @@
             if (rec instanceof SharedFormulaRecord) {
             	sharedFormulas.add(rec);
             }
+            if(rec instanceof EOFRecord) {
+                // End of current sheet. Ignore all subsequent shared formula records (Bugzilla 44449)
+                break;
+            }
         }
 
         // Now do the main processing sweep
@@ -156,6 +160,8 @@
                 //  for us
                 boolean found = false;
                 for (int i=sharedFormulas.size()-1;i>=0;i--) {
+                    // TODO - there is no junit test case to justify this reversed loop
+                    // perhaps it could just run in the normal direction?
                 	SharedFormulaRecord shrd = (SharedFormulaRecord)sharedFormulas.get(i);
                 	if (shrd.isFormulaInShared(formula)) {
                 		shrd.convertSharedFormulaRecord(formula);
@@ -164,9 +170,7 @@
                 	}
                 }
                 if (!found) {
-                	//Sometimes the shared formula flag "seems" to be errornously set,
-                	//cant really do much about that.
-                	//throw new RecordFormatException("Could not find appropriate shared formula");
+                    handleMissingSharedFormulaRecord(formula);
                 }
               }
             	
@@ -186,6 +190,24 @@
     }
 
     /**
+     * Sometimes the shared formula flag "seems" to be erroneously set, in which case there is no 
+     * call to <tt>SharedFormulaRecord.convertSharedFormulaRecord</tt> and hence the 
+     * <tt>parsedExpression</tt> field of this <tt>FormulaRecord</tt> will not get updated.<br/>
+     * As it turns out, this is not a problem, because in these circumstances, the existing value
+     * for <tt>parsedExpression</tt> is perfectly OK.<p/>
+     * 
+     * This method may also be used for setting breakpoints to help diagnose issues regarding the
+     * abnormally-set 'shared formula' flags. 
+     * (see TestValueRecordsAggregate.testSpuriousSharedFormulaFlag()).<p/>
+     * 
+     * The method currently does nothing but do not delete it without finding a nice home for this 
+     * comment.
+     */
+    private static void handleMissingSharedFormulaRecord(FormulaRecord formula) {
+        // could log an info message here since this is a fairly unusual occurrence.
+    }
+
+    /**
      * called by the class that is responsible for writing this sucker.
      * Subclasses should implement this so that their data is passed back in a
      * byte array.
@@ -300,7 +322,7 @@
       return rec;
     }
   
-  public class MyIterator implements Iterator {
+  private final class MyIterator implements Iterator {
     short nextColumn=-1;
     int nextRow,lastRow;
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AbstractFunctionPtg.java Sat Mar  8 03:49:00 2008
@@ -29,10 +29,13 @@
  * @author Andrew C. Oliver (acoliver at apache dot org)
  */
 public abstract class AbstractFunctionPtg extends OperationPtg {
-	//constant used allow a ptgAttr to be mapped properly for its functionPtg
-	public static final String ATTR_NAME = "specialflag";
-	    
-    public static final short INDEX_EXTERNAL = 255;
+
+    /**
+     * The name of the IF function (i.e. "IF").  Extracted as a constant for clarity.
+     */ 
+    public static final String FUNCTION_NAME_IF = "IF";
+    /** All external functions have function index 255 */
+    private static final short FUNCTION_INDEX_EXTERNAL = 255;
     
     private static BinaryTree map = produceHash(); 
     protected static Object[][] functionData = produceFunctionData();
@@ -66,6 +69,13 @@
     public String getName() {
         return lookupName(field_2_fnc_index);
     }
+    /**
+     * external functions get some special processing
+     * @return <code>true</code> if this is an external function
+     */
+    public boolean isExternalFunction() {
+        return field_2_fnc_index == FUNCTION_INDEX_EXTERNAL;
+    }
     
     public String toFormulaString(Workbook book) {
         return getName();
@@ -73,39 +83,57 @@
     
     public String toFormulaString(String[] operands) {
         StringBuffer buf = new StringBuffer();        
-          
-          if (field_2_fnc_index != 1) {
-              buf.append(getName());
-              buf.append('(');
-          }
-          if (operands.length >0) {
-              for (int i=0;i<operands.length;i++) {
-                  buf.append(operands[i]);
-                  buf.append(',');
-              }
-              buf.deleteCharAt(buf.length()-1);
-          }
-          if (field_2_fnc_index != 1) {
-            buf.append(")");
-          }
+        
+        if(isExternalFunction()) {
+            buf.append(operands[0]); // first operand is actually the function name
+            appendArgs(buf, 1, operands);
+        } else {
+            buf.append(getName());
+            appendArgs(buf, 0, operands);
+        }
         return buf.toString();
     }
+
+    private static void appendArgs(StringBuffer buf, int firstArgIx, String[] operands) {
+        buf.append('(');
+        for (int i=firstArgIx;i<operands.length;i++) {
+            if (i>firstArgIx) {
+                buf.append(',');
+            }
+            buf.append(operands[i]);
+        }
+        buf.append(")");
+    }
     
     public abstract void writeBytes(byte[] array, int offset);
     public abstract int getSize();
     
    
-    
-
+    /**
+     * Used to detect whether a function name found in a formula is one of the standard excel functions
+     * <p>
+     * The name matching is case insensitive.
+     * @return <code>true</code> if the name specifies a standard worksheet function, 
+     *  <code>false</code> if the name should be assumed to be an external function.
+     */
+    public static final boolean isInternalFunctionName(String name) {
+        return map.containsValue(name.toUpperCase());
+    }
     
     protected String lookupName(short index) {
         return ((String)map.get(new Integer(index))); 
     }
     
-    protected short lookupIndex(String name) {
-        Integer index = (Integer) map.getKeyForValue(name);
+    /**
+     * Resolves internal function names into function indexes.
+     * <p>
+     * The name matching is case insensitive.
+     * @return the standard worksheet function index if found, otherwise <tt>FUNCTION_INDEX_EXTERNAL</tt>
+     */
+    protected static short lookupIndex(String name) {
+        Integer index = (Integer) map.getKeyForValue(name.toUpperCase());
         if (index != null) return index.shortValue();
-        return INDEX_EXTERNAL;
+        return FUNCTION_INDEX_EXTERNAL;
     }
     
     /**
@@ -115,7 +143,7 @@
         BinaryTree dmap = new BinaryTree();
 
         dmap.put(new Integer(0),"COUNT");
-        dmap.put(new Integer(1),"specialflag");
+        dmap.put(new Integer(1),FUNCTION_NAME_IF);
         dmap.put(new Integer(2),"ISNA");
         dmap.put(new Integer(3),"ISERROR");
         dmap.put(new Integer(4),"SUM");
@@ -354,7 +382,7 @@
         dmap.put(new Integer(252),"FREQUENCY");
         dmap.put(new Integer(253),"ADDTOOLBAR");
         dmap.put(new Integer(254),"DELETETOOLBAR");
-        dmap.put(new Integer(255),"externalflag");
+        dmap.put(new Integer(FUNCTION_INDEX_EXTERNAL),"externalflag");
         dmap.put(new Integer(256),"RESETTOOLBAR");
         dmap.put(new Integer(257),"EVALUATE");
         dmap.put(new Integer(258),"GETTOOLBAR");

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java Sat Mar  8 03:49:00 2008
@@ -17,15 +17,13 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.hssf.util.AreaReference;
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.util.SheetReferences;
-
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.util.AreaReference;
+import org.apache.poi.hssf.util.CellReference;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
+import org.apache.poi.util.LittleEndian;
 
 
 /**
@@ -38,15 +36,15 @@
  * @version 1.0-pre
  */
 
-public class Area3DPtg extends Ptg
+public class Area3DPtg extends Ptg implements AreaI
 {
 	public final static byte sid = 0x3b;
 	private final static int SIZE = 11; // 10 + 1 for Ptg
 	private short field_1_index_extern_sheet;
-	private short field_2_first_row;
-	private short field_3_last_row;
-	private short field_4_first_column;
-	private short field_5_last_column;
+	private int field_2_first_row;
+	private int field_3_last_row;
+	private int field_4_first_column;
+	private int field_5_last_column;
 
 	private BitField rowRelative = BitFieldFactory.getInstance( 0x8000 );
 	private BitField colRelative = BitFieldFactory.getInstance( 0x4000 );
@@ -66,10 +64,24 @@
 	public Area3DPtg(RecordInputStream in)
 	{
 		field_1_index_extern_sheet = in.readShort();
-		field_2_first_row = in.readShort();
-		field_3_last_row = in.readShort();
-		field_4_first_column = in.readShort();
-		field_5_last_column = in.readShort();
+		field_2_first_row = in.readUShort();
+		field_3_last_row = in.readUShort();
+		field_4_first_column = in.readUShort();
+		field_5_last_column = in.readUShort();
+	}
+
+	public Area3DPtg(short firstRow, short lastRow, short firstColumn, short lastColumn,
+			boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative,
+			short externalSheetIndex) {
+		  setFirstRow(firstRow);
+		  setLastRow(lastRow);
+		  setFirstColumn(firstColumn);
+		  setLastColumn(lastColumn);
+		  setFirstRowRelative(firstRowRelative);
+		  setLastRowRelative(lastRowRelative);
+		  setFirstColRelative(firstColRelative);
+		  setLastColRelative(lastColRelative);
+		  setExternSheetIndex(externalSheetIndex);
 	}
 
 	public String toString()
@@ -87,7 +99,7 @@
 		buffer.append( "lastColRowRel = "
 				+ isLastRowRelative() ).append( "\n" );
 		buffer.append( "firstColRel   = " + isFirstColRelative() ).append( "\n" );
-		buffer.append( "lastColRel    = " + isLastColRelative() ).append( "\n" );
+		buffer.append( "lastColRel	= " + isLastColRelative() ).append( "\n" );
 		return buffer.toString();
 	}
 
@@ -95,10 +107,10 @@
 	{
 		array[0 + offset] = (byte) ( sid + ptgClass );
 		LittleEndian.putShort( array, 1 + offset, getExternSheetIndex() );
-		LittleEndian.putShort( array, 3 + offset, getFirstRow() );
-		LittleEndian.putShort( array, 5 + offset, getLastRow() );
-		LittleEndian.putShort( array, 7 + offset, getFirstColumnRaw() );
-		LittleEndian.putShort( array, 9 + offset, getLastColumnRaw() );
+		LittleEndian.putShort( array, 3 + offset, (short)getFirstRow() );
+		LittleEndian.putShort( array, 5 + offset, (short)getLastRow() );
+		LittleEndian.putShort( array, 7 + offset, (short)getFirstColumnRaw() );
+		LittleEndian.putShort( array, 9 + offset, (short)getLastColumnRaw() );
 	}
 
 	public int getSize()
@@ -116,32 +128,32 @@
 		field_1_index_extern_sheet = index;
 	}
 
-	public short getFirstRow()
+	public int getFirstRow()
 	{
 		return field_2_first_row;
 	}
 
-	public void setFirstRow( short row )
+	public void setFirstRow( int row )
 	{
 		field_2_first_row = row;
 	}
 
-	public short getLastRow()
+	public int getLastRow()
 	{
 		return field_3_last_row;
 	}
 
-	public void setLastRow( short row )
+	public void setLastRow( int row )
 	{
 		field_3_last_row = row;
 	}
 
-	public short getFirstColumn()
+	public int getFirstColumn()
 	{
-		return (short) ( field_4_first_column & 0xFF );
+		return field_4_first_column & 0xFF;
 	}
 
-	public short getFirstColumnRaw()
+	public int getFirstColumnRaw()
 	{
 		return field_4_first_column;
 	}
@@ -167,12 +179,12 @@
 		field_4_first_column = column;
 	}
 
-	public short getLastColumn()
+	public int getLastColumn()
 	{
-		return (short) ( field_5_last_column & 0xFF );
+		return field_5_last_column & 0xFF;
 	}
 
-	public short getLastColumnRaw()
+	public int getLastColumnRaw()
 	{
 		return field_5_last_column;
 	}
@@ -204,7 +216,7 @@
 	 */
 	public void setFirstRowRelative( boolean rel )
 	{
-		field_4_first_column = rowRelative.setShortBoolean( field_4_first_column, rel );
+		field_4_first_column = rowRelative.setBoolean( field_4_first_column, rel );
 	}
 
 	/**
@@ -212,7 +224,7 @@
 	 */
 	public void setFirstColRelative( boolean rel )
 	{
-		field_4_first_column = colRelative.setShortBoolean( field_4_first_column, rel );
+		field_4_first_column = colRelative.setBoolean( field_4_first_column, rel );
 	}
 
 	/**
@@ -221,7 +233,7 @@
 	 */
 	public void setLastRowRelative( boolean rel )
 	{
-		field_5_last_column = rowRelative.setShortBoolean( field_5_last_column, rel );
+		field_5_last_column = rowRelative.setBoolean( field_5_last_column, rel );
 	}
 
 	/**
@@ -229,7 +241,7 @@
 	 */
 	public void setLastColRelative( boolean rel )
 	{
-		field_5_last_column = colRelative.setShortBoolean( field_5_last_column, rel );
+		field_5_last_column = colRelative.setBoolean( field_5_last_column, rel );
 	}
 
 
@@ -243,39 +255,38 @@
 	public void setArea( String ref )
 	{
 		AreaReference ar = new AreaReference( ref );
-		CellReference[] crs = ar.getCells();
 		
-		CellReference firstCell = crs[0];
-		CellReference lastCell = firstCell;
-		if(crs.length > 1) {
-			lastCell = crs[1];
-		}
+		CellReference frstCell = ar.getFirstCell();
+		CellReference lastCell = ar.getLastCell();
 
-		setFirstRow(    (short) firstCell.getRow() );
-		setFirstColumn( (short) firstCell.getCol() );
-		setLastRow(     (short) lastCell.getRow() );
-		setLastColumn(  (short) lastCell.getCol() );
-		setFirstColRelative( !firstCell.isColAbsolute() );
+		setFirstRow(	(short) frstCell.getRow() );
+		setFirstColumn(		 frstCell.getCol() );
+		setLastRow(	 (short) lastCell.getRow() );
+		setLastColumn(		  lastCell.getCol() );
+		setFirstColRelative( !frstCell.isColAbsolute() );
 		setLastColRelative(  !lastCell.isColAbsolute() );
-		setFirstRowRelative( !firstCell.isRowAbsolute() );
+		setFirstRowRelative( !frstCell.isRowAbsolute() );
 		setLastRowRelative(  !lastCell.isRowAbsolute() );
 	}
 
-    /**
-     * @return text representation of this area reference that can be used in text
-     *  formulas. The sheet name will get properly delimited if required.
-     */
+	/**
+	 * @return text representation of this area reference that can be used in text
+	 *  formulas. The sheet name will get properly delimited if required.
+	 */
 	public String toFormulaString(Workbook book)
 	{
+		// First do the sheet name
 		StringBuffer retval = new StringBuffer();
 		String sheetName = Ref3DPtg.getSheetName(book, field_1_index_extern_sheet);
 		if(sheetName != null) {
 			SheetNameFormatter.appendFormat(retval, sheetName);
 			retval.append( '!' );
 		}
-		retval.append( ( new CellReference( getFirstRow(), getFirstColumn(), !isFirstRowRelative(), !isFirstColRelative() ) ).toString() );
-		retval.append( ':' );
-		retval.append( ( new CellReference( getLastRow(), getLastColumn(), !isLastRowRelative(), !isLastColRelative() ) ).toString() );
+		
+		// Now the normal area bit
+		retval.append( AreaPtg.toFormulaString(this, book) );
+		
+		// All done
 		return retval.toString();
 	}
 
@@ -292,7 +303,7 @@
 		ptg.field_3_last_row = field_3_last_row;
 		ptg.field_4_first_column = field_4_first_column;
 		ptg.field_5_last_column = field_5_last_column;
-            ptg.setClass(ptgClass);
+		ptg.setClass(ptgClass);
 		return ptg;
 	}
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaAPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaAPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaAPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaAPtg.java Sat Mar  8 03:49:00 2008
@@ -36,16 +36,14 @@
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 
-public class AreaAPtg
-    extends AreaPtg
-{
+public final class AreaAPtg extends AreaPtg {
     public final static short sid  = 0x65;
 
     protected AreaAPtg() {
       //Required for clone methods
     }
 
-    public AreaAPtg(short firstRow, short lastRow, short firstColumn, short lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
+    public AreaAPtg(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
       super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
     }
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java Sat Mar  8 03:49:00 2008
@@ -34,14 +34,18 @@
  */
 
 public class AreaPtg
-    extends Ptg
+    extends Ptg implements AreaI
 {
     public final static short sid  = 0x25;
     private final static int  SIZE = 9;
-    private short             field_1_first_row;
-    private short             field_2_last_row;
-    private short             field_3_first_column;
-    private short             field_4_last_column;
+    /** zero based, unsigned 16 bit */
+    private int             field_1_first_row;
+    /** zero based, unsigned 16 bit */
+    private int             field_2_last_row;
+    /** zero based, unsigned 8 bit */
+    private int             field_3_first_column;
+    /** zero based, unsigned 8 bit */
+    private int             field_4_last_column;
     
     private final static BitField   rowRelative = BitFieldFactory.getInstance(0x8000);
     private final static BitField   colRelative = BitFieldFactory.getInstance(0x4000);
@@ -53,17 +57,25 @@
    
     public AreaPtg(String arearef) {
         AreaReference ar = new AreaReference(arearef);
-        setFirstRow((short)ar.getCells()[0].getRow());
-        setFirstColumn((short)ar.getCells()[0].getCol());
-        setLastRow((short)ar.getCells()[1].getRow());
-        setLastColumn((short)ar.getCells()[1].getCol());
-        setFirstColRelative(!ar.getCells()[0].isColAbsolute());
-        setLastColRelative(!ar.getCells()[1].isColAbsolute());
-        setFirstRowRelative(!ar.getCells()[0].isRowAbsolute());
-        setLastRowRelative(!ar.getCells()[1].isRowAbsolute());        
+        CellReference firstCell = ar.getFirstCell();
+        CellReference lastCell = ar.getLastCell();
+        setFirstRow(firstCell.getRow());
+        setFirstColumn(firstCell.getCol());
+        setLastRow(lastCell.getRow());
+        setLastColumn(lastCell.getCol());
+        setFirstColRelative(!firstCell.isColAbsolute());
+        setLastColRelative(!lastCell.isColAbsolute());
+        setFirstRowRelative(!firstCell.isRowAbsolute());
+        setLastRowRelative(!lastCell.isRowAbsolute());        
     }
     
-    public AreaPtg(short firstRow, short lastRow, short firstColumn, short lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
+    public AreaPtg(int firstRow, int lastRow, int firstColumn, int lastColumn,
+            boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
+        
+        checkColumnBounds(firstColumn);
+        checkColumnBounds(lastColumn);
+        checkRowBounds(firstRow);
+        checkRowBounds(lastRow);
       setFirstRow(firstRow);
       setLastRow(lastRow);
       setFirstColumn(firstColumn);
@@ -74,12 +86,23 @@
       setLastColRelative(lastColRelative);
     }    
 
+    private static void checkColumnBounds(int colIx) {
+        if((colIx & 0x0FF) != colIx) {
+            throw new IllegalArgumentException("colIx (" + colIx + ") is out of range");
+        }
+    }
+    private static void checkRowBounds(int rowIx) {
+        if((rowIx & 0x0FFFF) != rowIx) {
+            throw new IllegalArgumentException("rowIx (" + rowIx + ") is out of range");
+        }
+    }
+
     public AreaPtg(RecordInputStream in)
     {
-        field_1_first_row    = in.readShort();
-        field_2_last_row     = in.readShort();
-        field_3_first_column = in.readShort();
-        field_4_last_column  = in.readShort();
+        field_1_first_row    = in.readUShort();
+        field_2_last_row     = in.readUShort();
+        field_3_first_column = in.readUShort();
+        field_4_last_column  = in.readUShort();
         //System.out.println(toString());
     }
     
@@ -108,10 +131,10 @@
 
     public void writeBytes(byte [] array, int offset) {
         array[offset] = (byte) (sid + ptgClass);
-        LittleEndian.putShort(array,offset+1,field_1_first_row);
-        LittleEndian.putShort(array,offset+3,field_2_last_row);
-        LittleEndian.putShort(array,offset+5,field_3_first_column);
-        LittleEndian.putShort(array,offset+7,field_4_last_column);        
+        LittleEndian.putShort(array,offset+1,(short)field_1_first_row);
+        LittleEndian.putShort(array,offset+3,(short)field_2_last_row);
+        LittleEndian.putShort(array,offset+5,(short)field_3_first_column);
+        LittleEndian.putShort(array,offset+7,(short)field_4_last_column);        
     }
 
     public int getSize()
@@ -122,42 +145,42 @@
     /**
      * @return the first row in the area
      */
-    public short getFirstRow()
+    public int getFirstRow()
     {
         return field_1_first_row;
     }
 
     /**
      * sets the first row
-     * @param row number (0-based)
+     * @param rowIx number (0-based)
      */
-    public void setFirstRow(short row)
-    {
-        field_1_first_row = row;
+    public void setFirstRow(int rowIx) {
+        checkRowBounds(rowIx);
+        field_1_first_row = rowIx;
     }
 
     /**
      * @return last row in the range (x2 in x1,y1-x2,y2)
      */
-    public short getLastRow()
+    public int getLastRow()
     {
         return field_2_last_row;
     }
 
     /**
-     * @param row last row number in the area 
+     * @param rowIx last row number in the area 
      */
-    public void setLastRow(short row)
-    {
-        field_2_last_row = row;
+    public void setLastRow(int rowIx) {
+        checkRowBounds(rowIx);
+        field_2_last_row = rowIx;
     }
 
     /**
      * @return the first column number in the area.
      */
-    public short getFirstColumn()
+    public int getFirstColumn()
     {
-        return columnMask.getShortValue(field_3_first_column);
+        return columnMask.getValue(field_3_first_column);
     }
 
     /**
@@ -165,7 +188,7 @@
      */
     public short getFirstColumnRaw()
     {
-        return field_3_first_column;
+        return (short) field_3_first_column; // TODO
     }
 
     /**
@@ -181,7 +204,7 @@
      * @param rel is relative or not.
      */
     public void setFirstRowRelative(boolean rel) {
-        field_3_first_column=rowRelative.setShortBoolean(field_3_first_column,rel);
+        field_3_first_column=rowRelative.setBoolean(field_3_first_column,rel);
     }
 
     /**
@@ -196,21 +219,21 @@
      * set whether the first column is relative 
      */
     public void setFirstColRelative(boolean rel) {
-        field_3_first_column=colRelative.setShortBoolean(field_3_first_column,rel);
+        field_3_first_column=colRelative.setBoolean(field_3_first_column,rel);
     }
 
     /**
      * set the first column in the area
      */
-    public void setFirstColumn(short column)
-    {
-    	field_3_first_column=columnMask.setShortValue(field_3_first_column, column);
+    public void setFirstColumn(int colIx) {
+        checkColumnBounds(colIx);
+    	field_3_first_column=columnMask.setValue(field_3_first_column, colIx);
     }
 
     /**
      * set the first column irespective of the bitmasks
      */
-    public void setFirstColumnRaw(short column)
+    public void setFirstColumnRaw(int column)
     {
         field_3_first_column = column;
     }
@@ -218,9 +241,9 @@
     /**
      * @return lastcolumn in the area
      */
-    public short getLastColumn()
+    public int getLastColumn()
     {
-        return columnMask.getShortValue(field_4_last_column);
+        return columnMask.getValue(field_4_last_column);
     }
 
     /**
@@ -228,7 +251,7 @@
      */
     public short getLastColumnRaw()
     {
-        return field_4_last_column;
+        return (short) field_4_last_column;
     }
 
     /**
@@ -245,7 +268,7 @@
      * <code>false</code>
      */
     public void setLastRowRelative(boolean rel) {
-        field_4_last_column=rowRelative.setShortBoolean(field_4_last_column,rel);
+        field_4_last_column=rowRelative.setBoolean(field_4_last_column,rel);
     }
 
     /**
@@ -260,16 +283,16 @@
      * set whether the last column should be relative or not
      */
     public void setLastColRelative(boolean rel) {
-        field_4_last_column=colRelative.setShortBoolean(field_4_last_column,rel);
+        field_4_last_column=colRelative.setBoolean(field_4_last_column,rel);
     }
     
 
     /**
      * set the last column in the area
      */
-    public void setLastColumn(short column)
-    {
-    	field_4_last_column=columnMask.setShortValue(field_4_last_column, column);
+    public void setLastColumn(int colIx) {
+        checkColumnBounds(colIx);
+    	field_4_last_column=columnMask.setValue(field_4_last_column, colIx);
     }
 
     /**
@@ -279,11 +302,20 @@
     {
         field_4_last_column = column;
     }
-
+    
     public String toFormulaString(Workbook book)
     {
-         return (new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative())).toString() + ":" +
-                (new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative())).toString();
+    	return toFormulaString(this, book);
+    }
+    protected static String toFormulaString(AreaI area, Workbook book) {
+    	CellReference topLeft = new CellReference(area.getFirstRow(),area.getFirstColumn(),!area.isFirstRowRelative(),!area.isFirstColRelative());
+    	CellReference botRight = new CellReference(area.getLastRow(),area.getLastColumn(),!area.isLastRowRelative(),!area.isLastColRelative());
+    	
+    	if(AreaReference.isWholeColumnReference(topLeft, botRight)) {
+    		return (new AreaReference(topLeft, botRight)).formatAsString();
+    	} else {
+    		return topLeft.formatAsString() + ":" + botRight.formatAsString(); 
+    	}
     }
 
     public byte getDefaultOperandClass() {

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaVPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaVPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaVPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/AreaVPtg.java Sat Mar  8 03:49:00 2008
@@ -36,7 +36,7 @@
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 
-public class AreaVPtg
+public final class AreaVPtg
     extends AreaPtg
 {
     public final static short sid  = 0x45;
@@ -45,7 +45,7 @@
       //Required for clone methods
     }
 
-    public AreaVPtg(short firstRow, short lastRow, short firstColumn, short lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
+    public AreaVPtg(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
       super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
     }
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java Sat Mar  8 03:49:00 2008
@@ -72,8 +72,10 @@
     	field_7_reserved = in.readByte();
     }
     
-    /** Read in the actual token (array) values. This occurs AFTER the last
-     * Ptg in the expression.
+    /** 
+     * Read in the actual token (array) values. This occurs 
+     * AFTER the last Ptg in the expression.
+     * See page 304-305 of Excel97-2007BinaryFileFormat(xls)Specification.pdf
      */
     public void readTokenValues(RecordInputStream in) {    	
         token_1_columns = (short)(0x00ff & in.readByte());
@@ -88,18 +90,17 @@
         token_3_arrayValues = new Object[token_1_columns][token_2_rows];
         
         for (int x=0;x<token_1_columns;x++) {
-        	for (int y=0;y<token_2_rows;y++) {
-        		byte grbit = in.readByte();
-        		if (grbit == 0x01) {
-			    token_3_arrayValues[x][y] = new Double(in.readDouble());
-        		} else if (grbit == 0x02) {
-        			//Ignore the doco, it is actually a unicode string with all the
-        			//trimmings ie 16 bit size, option byte etc
-        			token_3_arrayValues[x][y] = in.readUnicodeString();
-        		} else throw new RecordFormatException("Unknown grbit '"+grbit+"'");
-        	}
+			for (int y=0;y<token_2_rows;y++) {
+				byte grbit = in.readByte();
+				if (grbit == 0x01) {
+					token_3_arrayValues[x][y] = new Double(in.readDouble());
+				} else if (grbit == 0x02) {
+					//Ignore the doco, it is actually a unicode string with all the
+					//trimmings ie 16 bit size, option byte etc
+					token_3_arrayValues[x][y] = in.readUnicodeString();
+				} else throw new RecordFormatException("Unknown grbit '"+grbit+"' at " + x + "," + y + " with " + in.remaining() + " bytes left");
+			}
         }
-
     }
 
     public String toString()

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ErrPtg.java Sat Mar  8 03:49:00 2008
@@ -26,66 +26,67 @@
 /**
  * @author Daniel Noll (daniel at nuix dot com dot au)
  */
-public class ErrPtg extends Ptg
-{
+public final class ErrPtg extends Ptg {
+    
+    // convenient access to namespace
+    private static final HSSFErrorConstants EC = null;
+    
+    /** <b>#NULL!</b>  - Intersection of two cell ranges is empty */
+    public static final ErrPtg NULL_INTERSECTION = new ErrPtg(EC.ERROR_NULL); 
+    /** <b>#DIV/0!</b> - Division by zero */
+    public static final ErrPtg DIV_ZERO = new ErrPtg(EC.ERROR_DIV_0);
+    /** <b>#VALUE!</b> - Wrong type of operand */
+    public static final ErrPtg VALUE_INVALID = new ErrPtg(EC.ERROR_VALUE);
+    /** <b>#REF!</b> - Illegal or deleted cell reference */
+    public static final ErrPtg REF_INVALID = new ErrPtg(EC.ERROR_REF);
+    /** <b>#NAME?</b> - Wrong function or range name */
+    public static final ErrPtg NAME_INVALID = new ErrPtg(EC.ERROR_NAME); 
+    /** <b>#NUM!</b> - Value range overflow */
+    public static final ErrPtg NUM_ERROR = new ErrPtg(EC.ERROR_NUM);
+    /** <b>#N/A</b> - Argument or function not available */
+    public static final ErrPtg N_A = new ErrPtg(EC.ERROR_NA);
+    
+    
     public static final short sid  = 0x1c;
     private static final int  SIZE = 2;
-    private byte              field_1_error_code;
+    private int              field_1_error_code;
 
     /** Creates new ErrPtg */
 
-    public ErrPtg()
-    {
+    public ErrPtg(int errorCode) {
+        if(!HSSFErrorConstants.isValidCode(errorCode)) {
+            throw new IllegalArgumentException("Invalid error code (" + errorCode + ")");
+        }
+        field_1_error_code = errorCode;
     }
-
-    public ErrPtg(RecordInputStream in)
-    {
-        field_1_error_code = in.readByte();
+ 
+    public ErrPtg(RecordInputStream in) {
+        this(in.readByte());
     }
 
     public void writeBytes(byte [] array, int offset)
     {
         array[offset] = (byte) (sid + ptgClass);
-        array[offset + 1] = field_1_error_code;
+        array[offset + 1] = (byte)field_1_error_code;
     }
 
-    public String toFormulaString(Workbook book)
-    {
-        switch(field_1_error_code)
-        {
-            case HSSFErrorConstants.ERROR_NULL:
-                return "#NULL!";
-            case HSSFErrorConstants.ERROR_DIV_0:
-                return "#DIV/0!";
-            case HSSFErrorConstants.ERROR_VALUE:
-                return "#VALUE!";
-            case HSSFErrorConstants.ERROR_REF:
-                return "#REF!";
-            case HSSFErrorConstants.ERROR_NAME:
-                return "#NAME?";
-            case HSSFErrorConstants.ERROR_NUM:
-                return "#NUM!";
-            case HSSFErrorConstants.ERROR_NA:
-                return "#N/A";
-        }
-
-        // Shouldn't happen anyway.  Excel docs say that this is returned for all other codes.
-        return "#N/A";
+    public String toFormulaString(Workbook book) {
+        return HSSFErrorConstants.getText(field_1_error_code);
     }
 
-    public int getSize()
-    {
+    public int getSize() {
         return SIZE;
     }
 
-    public byte getDefaultOperandClass()
-    {
+    public byte getDefaultOperandClass() {
         return Ptg.CLASS_VALUE;
     }
 
     public Object clone() {
-        ErrPtg ptg = new ErrPtg();
-        ptg.field_1_error_code = field_1_error_code;
-        return ptg;
+        return new ErrPtg(field_1_error_code);
+    }
+
+    public int getErrorCode() {
+        return field_1_error_code;
     }
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/FuncPtg.java Sat Mar  8 03:49:00 2008
@@ -63,6 +63,10 @@
         }   
         
     }
+    public FuncPtg(int functionIndex, int numberOfParameters) {
+        field_2_fnc_index = (short) functionIndex;
+        numParams = numberOfParameters;
+    }
     
      public void writeBytes(byte[] array, int offset) {
         array[offset+0]= (byte) (sid + ptgClass);

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/IntPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/IntPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/IntPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/IntPtg.java Sat Mar  8 03:49:00 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -16,12 +15,6 @@
    limitations under the License.
 ==================================================================== */
 
-
-/*
- * IntPtg.java
- *
- * Created on October 29, 2001, 7:37 PM
- */
 package org.apache.poi.hssf.record.formula;
 
 import org.apache.poi.util.LittleEndian;
@@ -29,64 +22,45 @@
 import org.apache.poi.hssf.record.RecordInputStream;
 
 /**
- * Integer (unsigned short intger)
+ * Integer (unsigned short integer)
  * Stores an unsigned short value (java int) in a formula
  * @author  Andrew C. Oliver (acoliver at apache dot org)
  * @author Jason Height (jheight at chariot dot net dot au)
  */
+public final class IntPtg extends Ptg {
+    // 16 bit unsigned integer
+    private static final int MIN_VALUE = 0x0000;
+    private static final int MAX_VALUE = 0xFFFF;
+    
+    /**
+     * Excel represents integers 0..65535 with the tInt token. 
+     * @return <code>true</code> if the specified value is within the range of values 
+     * <tt>IntPtg</tt> can represent. 
+     */
+    public static boolean isInRange(int i) {
+        return i>=MIN_VALUE && i <=MAX_VALUE;
+    }
 
-public class IntPtg
-    extends Ptg
-{
     public final static int  SIZE = 3;
     public final static byte sid  = 0x1e;
     private int            field_1_value;
   
-    private IntPtg() {
-      //Required for clone methods
+    public IntPtg(RecordInputStream in) {
+        this(in.readUShort());
     }
 
-    public IntPtg(RecordInputStream in)
-    {
-        setValue(in.readUShort());
-    }
-    
-    
-    // IntPtg should be able to create itself, shouldnt have to call setValue
-    public IntPtg(String formulaToken) {
-        setValue(Integer.parseInt(formulaToken));
-    }
 
-    /**
-     * Sets the wrapped value.
-     * Normally you should call with a positive int.
-     */
-    public void setValue(int value)
-    {
-        if(value < 0 || value > (Short.MAX_VALUE + 1)*2 )
-            throw new IllegalArgumentException("Unsigned short is out of range: " + value);
+    public IntPtg(int value) {
+        if(!isInRange(value)) {
+            throw new IllegalArgumentException("value is out of range: " + value);
+        }
         field_1_value = value;
     }
 
-    /**
-     * Returns the value as a short, which may have
-     *  been wrapped into negative numbers
-     */
-    public int getValue()
-    {
+    public int getValue() {
         return field_1_value;
     }
 
-    /**
-     * Returns the value as an unsigned positive int.
-     */
-    public int getValueAsInt()
-    {
-    	if(field_1_value < 0) {
-    		return (Short.MAX_VALUE + 1)*2 + field_1_value;
-    	}
-        return field_1_value;
-    }
 
     public void writeBytes(byte [] array, int offset)
     {
@@ -94,20 +68,25 @@
         LittleEndian.putUShort(array, offset + 1, getValue());
     }
 
-    public int getSize()
-    {
+    public int getSize() {
         return SIZE;
     }
 
-    public String toFormulaString(Workbook book)
-    {
-        return "" + getValue();
+    public String toFormulaString(Workbook book) {
+        return String.valueOf(getValue());
+    }
+    public byte getDefaultOperandClass() {
+        return Ptg.CLASS_VALUE;
     }
- public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}   
 
-   public Object clone() {
-     IntPtg ptg = new IntPtg();
-     ptg.field_1_value = field_1_value;
-     return ptg;
-   }
+    public Object clone() {
+     return new IntPtg(field_1_value);
+    }
+    public String toString() {
+        StringBuffer sb = new StringBuffer(64);
+        sb.append(getClass().getName()).append(" [");
+        sb.append(field_1_value);
+        sb.append("]");
+        return sb.toString();
+    }
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NamePtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NamePtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NamePtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NamePtg.java Sat Mar  8 03:49:00 2008
@@ -33,6 +33,7 @@
 {
     public final static short sid  = 0x23;
     private final static int  SIZE = 5;
+    /** one-based index to defined name record */
     private short             field_1_label_index;
     private short             field_2_zero;   // reserved must be 0
     boolean xtra=false;
@@ -42,24 +43,32 @@
       //Required for clone methods
     }
 
-    /** Creates new NamePtg */
-
-    public NamePtg(String name, Workbook book)
-    {
-        final short n = (short) (book.getNumNames() + 1);
+    /**
+     * Creates new NamePtg and sets its name index to that of the corresponding defined name record
+     * in the workbook.  The search for the name record is case insensitive.  If it is not found, 
+     * it gets created.
+     */
+    public NamePtg(String name, Workbook book) {
+        field_1_label_index = (short)(1+getOrCreateNameRecord(book, name)); // convert to 1-based
+    }
+    /**
+     * @return zero based index of the found or newly created defined name record. 
+     */
+    private static final int getOrCreateNameRecord(Workbook book, String name) {
+        // perhaps this logic belongs in Workbook
+        int countNames = book.getNumNames();
         NameRecord rec;
-        for (short i = 1; i < n; i++) {
-            rec = book.getNameRecord(i - 1);
-            if (name.equals(rec.getNameText())) {
-                field_1_label_index = i;
-                return;
+        for (int i = 0; i < countNames; i++) {
+            rec = book.getNameRecord(i);
+            if (name.equalsIgnoreCase(rec.getNameText())) {
+                return i; 
             }
         }
         rec = new NameRecord();
         rec.setNameText(name);
         rec.setNameTextLength((byte) name.length());
         book.addName(rec);
-        field_1_label_index = n;
+        return countNames;
     }
 
     /** Creates new NamePtg */
@@ -70,6 +79,13 @@
         field_1_label_index = in.readShort();
         field_2_zero        = in.readShort();
         //if (data[offset+6]==0) xtra=true;
+    }
+    
+    /**
+     * @return zero based index to a defined name record in the LinkTable
+     */
+    public int getIndex() {
+        return field_1_label_index-1; // convert to zero based
     }
 
     public void writeBytes(byte [] array, int offset)

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/NameXPtg.java Sat Mar  8 03:49:00 2008
@@ -25,13 +25,11 @@
  *
  * @author  aviks
  */
-
-public class NameXPtg extends Ptg
-{
+public final class NameXPtg extends Ptg {
     public final static short sid  = 0x39;
     private final static int  SIZE = 7;
-    private short             field_1_ixals;   // index to externsheet record
-    private short             field_2_ilbl;    //index to name or externname table(1 based)
+    private short             field_1_ixals;   // index to REF entry in externsheet record
+    private short             field_2_ilbl;    //index to defined name or externname table(1 based)
     private short            field_3_reserved;   // reserved must be 0
 
 
@@ -41,13 +39,6 @@
 
     /** Creates new NamePtg */
 
-    public NameXPtg(String name)
-    {
-        //TODO
-    }
-
-    /** Creates new NamePtg */
-
     public NameXPtg(RecordInputStream in)
     {
         field_1_ixals        = in.readShort();
@@ -72,7 +63,8 @@
 
     public String toFormulaString(Workbook book)
     {
-        return "NO IDEA - NAME";
+        // -1 to convert definedNameIndex from 1-based to zero-based
+        return book.resolveNameXText(field_1_ixals, field_2_ilbl-1); 
     }
     
     public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java Sat Mar  8 03:49:00 2008
@@ -18,16 +18,14 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.util.LittleEndian;
-
-import org.apache.poi.hssf.util.RangeAddress;
+import org.apache.poi.hssf.model.Workbook;
+import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.hssf.util.RangeAddress;
 import org.apache.poi.hssf.util.SheetReferences;
-import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.util.BitField;
 import org.apache.poi.util.BitFieldFactory;
-import org.apache.poi.hssf.model.Workbook;
-import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.util.LittleEndian;
 
 /**
  * Title:        Reference 3D Ptg <P>
@@ -42,8 +40,14 @@
     public final static byte sid  = 0x3a;
     private final static int  SIZE = 7; // 6 + 1 for Ptg
     private short             field_1_index_extern_sheet;
-    private short             field_2_row;
-    private short             field_3_column;
+    /** The row index - zero based unsigned 16 bit value */
+    private int            field_2_row;
+    /** Field 2 
+     * - lower 8 bits is the zero based unsigned byte column index 
+     * - bit 16 - isRowRelative
+     * - bit 15 - isColumnRelative 
+     */
+    private int             field_3_column;
     private BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
     private BitField         colRelative = BitFieldFactory.getInstance(0x4000);
 
@@ -58,8 +62,8 @@
     
     public Ref3DPtg(String cellref, short externIdx ) {
         CellReference c= new CellReference(cellref);
-        setRow((short) c.getRow());
-        setColumn((short) c.getCol());
+        setRow(c.getRow());
+        setColumn(c.getCol());
         setColRelative(!c.isColAbsolute());
         setRowRelative(!c.isRowAbsolute());   
         setExternSheetIndex(externIdx);
@@ -81,8 +85,8 @@
     public void writeBytes(byte [] array, int offset) {
         array[ 0 + offset ] = (byte) (sid + ptgClass);
         LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
-        LittleEndian.putShort(array, 3 + offset , getRow());
-        LittleEndian.putShort(array, 5 + offset , getColumnRaw());
+        LittleEndian.putShort(array, 3 + offset , (short)getRow());
+        LittleEndian.putShort(array, 5 + offset , (short)getColumnRaw());
     }
 
     public int getSize() {
@@ -97,19 +101,19 @@
         field_1_index_extern_sheet = index;
     }
 
-    public short getRow() {
+    public int getRow() {
         return field_2_row;
     }
 
-    public void setRow(short row) {
+    public void setRow(int row) {
         field_2_row = row;
     }
 
-    public short getColumn() {
-        return ( short ) (field_3_column & 0xFF);
+    public int getColumn() {
+        return field_3_column & 0xFF;
     }
 
-    public short getColumnRaw() {
+    public int getColumnRaw() {
         return field_3_column;
     }
 
@@ -119,7 +123,7 @@
     }
     
     public void setRowRelative(boolean rel) {
-        field_3_column=rowRelative.setShortBoolean(field_3_column,rel);
+        field_3_column=rowRelative.setBoolean(field_3_column,rel);
     }
     
     public boolean isColRelative()
@@ -128,7 +132,7 @@
     }
     
     public void setColRelative(boolean rel) {
-        field_3_column=colRelative.setShortBoolean(field_3_column,rel);
+        field_3_column=colRelative.setBoolean(field_3_column,rel);
     }
     public void setColumn(short column) {
         field_3_column &= 0xFF00;
@@ -183,7 +187,7 @@
             SheetNameFormatter.appendFormat(retval, sheetName);
             retval.append( '!' );
         }
-        retval.append((new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).toString()); 
+        retval.append((new CellReference(getRow(),getColumn(),!isRowRelative(),!isColRelative())).formatAsString()); 
         return retval.toString();
     }
 
@@ -197,5 +201,4 @@
      ptg.setClass(ptgClass);
      return ptg;
    }
-
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefAPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefAPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefAPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefAPtg.java Sat Mar  8 03:49:00 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -16,34 +15,23 @@
    limitations under the License.
 ==================================================================== */
 
-/*
- * ValueReferencePtg.java
- *
- * Created on November 21, 2001, 5:27 PM
- */
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.BitField;
-
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
 
 /**
  * RefNAPtg
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 
-public class RefAPtg extends ReferencePtg
-{
+public final class RefAPtg extends ReferencePtg {
     public final static byte sid  = 0x64;
 
     protected RefAPtg() {
       super();
     }
 
-    public RefAPtg(short row, short column, boolean isRowRelative, boolean isColumnRelative) {
+    public RefAPtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
       super(row, column, isRowRelative, isColumnRelative);
     }
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefVPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefVPtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefVPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefVPtg.java Sat Mar  8 03:49:00 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -18,27 +17,20 @@
 
 package org.apache.poi.hssf.record.formula;
 
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.BitField;
-
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.hssf.model.Workbook;
 
 /**
  * RefVPtg
  * @author Jason Height (jheight at chariot dot net dot au)
  */
-
-public class RefVPtg extends ReferencePtg
-{
+public final class RefVPtg extends ReferencePtg {
   public final static byte sid  = 0x44;
 
   protected RefVPtg() {
     super();
   }
 
-  public RefVPtg(short row, short column, boolean isRowRelative, boolean isColumnRelative) {
+  public RefVPtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
     super(row, column, isRowRelative, isColumnRelative);
   }
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java Sat Mar  8 03:49:00 2008
@@ -31,26 +31,22 @@
  * @author Jason Height (jheight at chariot dot net dot au)
  */
 
-public class ReferencePtg extends Ptg
-{
+public class ReferencePtg extends Ptg {
     private final static int SIZE = 5;
     public final static byte sid  = 0x24;
     private final static int MAX_ROW_NUMBER = 65536;             
-    //public final static byte sid = 0x44;
 
-   /** 
-     * The row number, between 0 and 65535, but stored as a signed
-     *  short between -32767 and 32768.
-     * Take care about which version you fetch back!
+   /** The row index - zero based unsigned 16 bit value */
+    private int            field_1_row;
+    /** Field 2 
+     * - lower 8 bits is the zero based unsigned byte column index 
+     * - bit 16 - isRowRelative
+     * - bit 15 - isColumnRelative 
      */
-    private short            field_1_row;
-    /**
-     * The column number, between 0 and ??
-     */
-    private short            field_2_col;
-    private BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
-    private BitField         colRelative = BitFieldFactory.getInstance(0x4000);
-    private BitField         column      = BitFieldFactory.getInstance(0x3FFF);
+    private int            field_2_col;
+    private static final BitField         rowRelative = BitFieldFactory.getInstance(0x8000);
+    private static final BitField         colRelative = BitFieldFactory.getInstance(0x4000);
+    private static final BitField         column      = BitFieldFactory.getInstance(0x00FF);
 
     protected ReferencePtg() {
       //Required for clone methods
@@ -62,13 +58,13 @@
      */
     public ReferencePtg(String cellref) {
         CellReference c= new CellReference(cellref);
-        setRow((short) c.getRow());
-        setColumn((short) c.getCol());
+        setRow(c.getRow());
+        setColumn(c.getCol());
         setColRelative(!c.isColAbsolute());
         setRowRelative(!c.isRowAbsolute());
     }
     
-    public ReferencePtg(short row, short column, boolean isRowRelative, boolean isColumnRelative) {
+    public ReferencePtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
       setRow(row);
       setColumn(column);
       setRowRelative(isRowRelative);
@@ -79,8 +75,8 @@
 
     public ReferencePtg(RecordInputStream in)
     {
-        field_1_row = in.readShort();
-        field_2_col = in.readShort();
+        field_1_row = in.readUShort();
+        field_2_col = in.readUShort();
     }
     
     public String getRefPtgName() {
@@ -104,33 +100,23 @@
     {
         array[offset] = (byte) (sid + ptgClass);
 
-        LittleEndian.putShort(array,offset+1,field_1_row);
-        LittleEndian.putShort(array,offset+3,field_2_col);
+        LittleEndian.putShort(array, offset+1, (short)field_1_row);
+        LittleEndian.putShort(array, offset+3, (short)field_2_col);
     }
 
-    public void setRow(short row)
-    {
-        field_1_row = row;
-    }
     public void setRow(int row)
     {
         if(row < 0 || row >= MAX_ROW_NUMBER) {
            throw new IllegalArgumentException("The row number, when specified as an integer, must be between 0 and " + MAX_ROW_NUMBER);
         }
-        
-        // Save, wrapping as needed
-        if(row > Short.MAX_VALUE) {
-        	field_1_row = (short)(row - MAX_ROW_NUMBER);
-        } else {
-        	field_1_row = (short)row;
-        }
+        field_1_row = row;
     }
 
     /**
      * Returns the row number as a short, which will be
      *  wrapped (negative) for values between 32769 and 65535
      */
-    public short getRow()
+    public int getRow()
     {
         return field_1_row;
     }
@@ -151,7 +137,7 @@
     }
     
     public void setRowRelative(boolean rel) {
-        field_2_col=rowRelative.setShortBoolean(field_2_col,rel);
+        field_2_col=rowRelative.setBoolean(field_2_col,rel);
     }
     
     public boolean isColRelative()
@@ -160,27 +146,29 @@
     }
     
     public void setColRelative(boolean rel) {
-        field_2_col=colRelative.setShortBoolean(field_2_col,rel);
+        field_2_col=colRelative.setBoolean(field_2_col,rel);
     }
 
-    public void setColumnRaw(short col)
+    public void setColumnRaw(int col)
     {
         field_2_col = col;
     }
 
-    public short getColumnRaw()
+    public int getColumnRaw()
     {
         return field_2_col;
     }
 
-    public void setColumn(short col)
+    public void setColumn(int col)
     {
-    	field_2_col = column.setShortValue(field_2_col, col);
+        if(col < 0 || col > 0x100) {
+            throw new IllegalArgumentException("Specified colIx (" + col + ") is out of range");
+        }
+    	field_2_col = column.setValue(field_2_col, col);
     }
 
-    public short getColumn()
-    {
-    	return column.getShortValue(field_2_col);
+    public int getColumn() {
+    	return column.getValue(field_2_col);
     }
 
     public int getSize()
@@ -191,7 +179,7 @@
     public String toFormulaString(Workbook book)
     {
         //TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
-        return (new CellReference(getRowAsInt(),getColumn(),!isRowRelative(),!isColRelative())).toString();
+        return (new CellReference(getRowAsInt(),getColumn(),!isRowRelative(),!isColRelative())).formatAsString();
     }
     
     public byte getDefaultOperandClass() {

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/SheetNameFormatter.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/SheetNameFormatter.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/SheetNameFormatter.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/SheetNameFormatter.java Sat Mar  8 03:49:00 2008
@@ -26,7 +26,7 @@
  * 
  * @author Josh Micich
  */
-final class SheetNameFormatter {
+public final class SheetNameFormatter {
 	
 	private static final String BIFF8_LAST_COLUMN = "IV";
 	private static final int BIFF8_LAST_COLUMN_TEXT_LEN = BIFF8_LAST_COLUMN.length();

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Sat Mar  8 03:49:00 2008
@@ -456,7 +456,7 @@
                 boolRec.setColumn(col);
                 if (setValue)
                 {
-                    boolRec.setValue(getBooleanCellValue());
+                    boolRec.setValue(convertCellValueToBoolean());
                 }
                 boolRec.setXFIndex(styleIndex);
                 boolRec.setRow(row);
@@ -644,7 +644,7 @@
             
             //only set to default if there is no extended format index already set
             if (rec.getXFIndex() == (short)0) rec.setXFIndex(( short ) 0x0f);
-            FormulaParser fp = new FormulaParser(formula+";",book);
+            FormulaParser fp = new FormulaParser(formula, book);
             fp.parse();
             Ptg[] ptg  = fp.getRPNPtg();
             int   size = 0;
@@ -829,6 +829,34 @@
             setCellType(CELL_TYPE_ERROR, false, row, col, styleIndex);
         }
         (( BoolErrRecord ) record).setValue(value);
+    }
+    /**
+     * Chooses a new boolean value for the cell when its type is changing.<p/>
+     * 
+     * Usually the caller is calling setCellType() with the intention of calling 
+     * setCellValue(boolean) straight afterwards.  This method only exists to give
+     * the cell a somewhat reasonable value until the setCellValue() call (if at all).
+     * TODO - perhaps a method like setCellTypeAndValue(int, Object) should be introduced to avoid this
+     */
+    private boolean convertCellValueToBoolean() {
+        
+        switch (cellType) {
+            case CELL_TYPE_BOOLEAN:
+                return (( BoolErrRecord ) record).getBooleanValue();
+            case CELL_TYPE_STRING:
+                return Boolean.valueOf(((StringRecord)record).getString()).booleanValue();
+            case CELL_TYPE_NUMERIC:
+                return ((NumberRecord)record).getValue() != 0;
+
+            // All other cases convert to false
+            // These choices are not well justified.
+            case CELL_TYPE_FORMULA:  
+                // should really evaluate, but HSSFCell can't call HSSFFormulaEvaluator
+            case CELL_TYPE_ERROR:
+            case CELL_TYPE_BLANK:
+                return false;  
+        }
+        throw new RuntimeException("Unexpected cell type (" + cellType + ")");
     }
 
     /**

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFErrorConstants.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFErrorConstants.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFErrorConstants.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFErrorConstants.java Sat Mar  8 03:49:00 2008
@@ -15,26 +15,68 @@
    limitations under the License.
 ==================================================================== */
 
-
-/*
- * HSSFErrorConstants.java
- *
- * Created on January 19, 2002, 9:30 AM
- */
 package org.apache.poi.hssf.usermodel;
 
 /**
- * contains constants representing Excel error codes.
+ * Contains raw Excel error codes (as defined in OOO's excelfileformat.pdf (2.5.6)
+ * 
  * @author  Michael Harhen
  */
-
-public interface HSSFErrorConstants
-{
-    public static final byte ERROR_NULL  = 0x00;   // #NULL!
-    public static final byte ERROR_DIV_0 = 0x07;   // #DIV/0!
-    public static final byte ERROR_VALUE = 0x0f;   // #VALUE!
-    public static final byte ERROR_REF   = 0x17;   // #REF!
-    public static final byte ERROR_NAME  = 0x1d;   // #NAME?
-    public static final byte ERROR_NUM   = 0x24;   // #NUM!
-    public static final byte ERROR_NA    = 0x2a;   // #N/A
+public final class HSSFErrorConstants {
+    private HSSFErrorConstants() {
+        // no instances of this class
+    }
+    
+    /** <b>#NULL!</b>  - Intersection of two cell ranges is empty */
+    public static final int ERROR_NULL = 0x00;
+    /** <b>#DIV/0!</b> - Division by zero */
+    public static final int ERROR_DIV_0 = 0x07;
+    /** <b>#VALUE!</b> - Wrong type of operand */
+    public static final int ERROR_VALUE = 0x0F; 
+    /** <b>#REF!</b> - Illegal or deleted cell reference */
+    public static final int ERROR_REF = 0x17;  
+    /** <b>#NAME?</b> - Wrong function or range name */
+    public static final int ERROR_NAME = 0x1D; 
+    /** <b>#NUM!</b> - Value range overflow */
+    public static final int ERROR_NUM = 0x24; 
+    /** <b>#N/A</b> - Argument or function not available */
+    public static final int ERROR_NA = 0x2A;
+    
+    
+    /**
+     * @return Standard Excel error literal for the specified error code. 
+     * @throws IllegalArgumentException if the specified error code is not one of the 7 
+     * standard error codes
+     */
+    public static final String getText(int errorCode) {
+        switch(errorCode) {
+            case ERROR_NULL:  return "#NULL!";
+            case ERROR_DIV_0: return "#DIV/0!";
+            case ERROR_VALUE: return "#VALUE!";
+            case ERROR_REF:   return "#REF!";
+            case ERROR_NAME:  return "#NAME?";
+            case ERROR_NUM:   return "#NUM!";
+            case ERROR_NA:    return "#N/A";
+        }
+        throw new IllegalArgumentException("Bad error code (" + errorCode + ")");
+    }
+    
+    /**
+     * @return <code>true</code> if the specified error code is a standard Excel error code. 
+     */
+    public static final boolean isValidCode(int errorCode) {
+        // This method exists because it would be bad to force clients to catch 
+        // IllegalArgumentException if there were potential for passing an invalid error code.  
+        switch(errorCode) {
+            case ERROR_NULL:
+            case ERROR_DIV_0:
+            case ERROR_VALUE:
+            case ERROR_REF:
+            case ERROR_NAME:
+            case ERROR_NUM:
+            case ERROR_NA:
+                return true;
+        }
+        return false;
+    }
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPalette.java Sat Mar  8 03:49:00 2008
@@ -100,9 +100,11 @@
         for (short i = (short) PaletteRecord.FIRST_COLOR_INDEX; b != null;
             b = palette.getColor(++i))
         {
-            int colorDistance = red - b[0] + green - b[1] + blue - b[2];
+            int colorDistance = Math.abs(red - b[0]) + 
+            	Math.abs(green - b[1]) + Math.abs(blue - b[2]);
             if (colorDistance < minColorDistance)
             {
+                minColorDistance = colorDistance;
                 result = getColor(i);
             }
         }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java Sat Mar  8 03:49:00 2008
@@ -159,28 +159,25 @@
      * @param cell to remove
      */
     public void removeCell(Cell cell) {
-    	removeCell(cell, true);
+    	removeCell((HSSFCell) cell, true);
     }
-    
-    private void removeCell(Cell cell, boolean alsoRemoveRecords) {
-        
-        HSSFCell hcell = (HSSFCell) cell;
+    private void removeCell(HSSFCell cell, boolean alsoRemoveRecords) {
     	if(alsoRemoveRecords) {
-	        CellValueRecordInterface cval = hcell.getCellValueRecord();
+	        CellValueRecordInterface cval = cell.getCellValueRecord();
 	        sheet.removeValueRecord(getRowNum(), cval);
     	}
     	
-        short column=hcell.getCellNum();
-        if(hcell!=null && column<cells.length)
+        short column=cell.getCellNum();
+        if(cell!=null && column<cells.length)
         {
           cells[column]=null;
         }
 
-        if (hcell.getCellNum() == row.getLastCol())
+        if (cell.getCellNum() == row.getLastCol())
         {
             row.setLastCol(findLastCell(row.getLastCol()));
         }
-        if (hcell.getCellNum() == row.getFirstCol())
+        if (cell.getCellNum() == row.getFirstCol())
         {
             row.setFirstCol(findFirstCell(row.getFirstCol()));
         }
@@ -471,6 +468,7 @@
      * @return cell iterator of the physically defined cells.  Note element 4 may
      * actually be row cell depending on how many are defined!
      */
+
     public Iterator cellIterator()
     {
       return new CellIterator();

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Sat Mar  8 03:49:00 2008
@@ -414,7 +414,7 @@
 
        //formula fields ( size and data )
        String str_formula = obj_validation.getFirstFormula();
-       FormulaParser fp = new FormulaParser(str_formula+";",book);
+       FormulaParser fp = new FormulaParser(str_formula, book);
        fp.parse();
        Stack ptg_arr = new Stack();
        Ptg[] ptg  = fp.getRPNPtg();
@@ -438,7 +438,7 @@
        if ( obj_validation.getSecondFormula() != null )
        {
          str_formula = obj_validation.getSecondFormula();
-         fp = new FormulaParser(str_formula+";",book);
+         fp = new FormulaParser(str_formula, book);
          fp.parse();
          ptg_arr = new Stack();
          ptg  = fp.getRPNPtg();
@@ -642,10 +642,17 @@
     }
 
     /**
-     * Determine whether printed output for this sheet will be vertically centered.
+     * TODO: Boolean not needed, remove after next release
+     * @deprecated use getVerticallyCenter() instead
      */
+    public boolean getVerticallyCenter(boolean value) {
+        return getVerticallyCenter();
+    }
 
-    public boolean getVerticallyCenter(boolean value)
+    /**
+     * Determine whether printed output for this sheet will be vertically centered.
+     */
+    public boolean getVerticallyCenter()
     {
         VCenterRecord record =
                 (VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid);

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=634936&r1=634935&r2=634936&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Sat Mar  8 03:49:00 2008
@@ -180,10 +180,7 @@
             throws IOException
     {
         this.preserveNodes = preserveNodes;
-
-        // Read in the HPSF properties
         this.filesystem = fs;
-        readProperties();
         
         // If we're not preserving nodes, don't track the
         //  POIFS any more
@@ -1134,12 +1131,12 @@
 	public void setPrintArea(int sheetIndex, int startColumn, int endColumn,
 							  int startRow, int endRow) {
 
-		//using absolute references because they dont get copied and pasted anyway
+		//using absolute references because they don't get copied and pasted anyway
 		CellReference cell = new CellReference(startRow, startColumn, true, true);
-		String reference = cell.toString();
+		String reference = cell.formatAsString();
 
 		cell = new CellReference(endRow, endColumn, true, true);
-		reference = reference+":"+cell.toString();
+		reference = reference+":"+cell.formatAsString();
 
 		setPrintArea(sheetIndex, reference);
 	}
@@ -1397,6 +1394,13 @@
         }
     }
 
+    /**
+     * Is the workbook protected with a password (not encrypted)?
+     */
+    public boolean isWriteProtected() {
+    	return this.workbook.isWriteProtected();
+    }
+    
     /**
      * protect a workbook with a password (not encypted, just sets writeprotect
      * flags and the password.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message