You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2009/05/19 18:29:53 UTC

svn commit: r776377 [3/6] - in /poi/trunk/src/java/org/apache/poi: ddf/ hssf/model/ hssf/record/ hssf/record/aggregates/ hssf/record/cont/ hssf/record/formula/ hssf/record/formula/eval/ hssf/usermodel/ hssf/util/ poifs/dev/ ss/ ss/formula/ ss/formula/e...

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFHyperlink.java Tue May 19 16:29:51 2009
@@ -1,220 +1,220 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-package org.apache.poi.hssf.usermodel;
-
-import org.apache.poi.hssf.record.HyperlinkRecord;
-import org.apache.poi.ss.usermodel.Hyperlink;
-
-/**
- * Represents an Excel hyperlink.
- *
- * @author Yegor Kozlov (yegor at apache dot org)
- */
-public class HSSFHyperlink implements Hyperlink {
-
-    /**
-     * Link to a existing file or web page
-     */
-    public static final int LINK_URL = 1;
-
-    /**
-     * Link to a place in this document
-     */
-    public static final int LINK_DOCUMENT = 2;
-
-    /**
-     * Link to an E-mail address
-     */
-    public static final int LINK_EMAIL = 3;
-
-    /**
-     * Link to a file
-     */
-    public static final int LINK_FILE = 4;
-
-    /**
-     * Low-level record object that stores the actual hyperlink data
-     */
-    protected HyperlinkRecord record = null;
-
-    /**
-     * If we create a new hypelrink remember its type
-     */
-    protected int link_type;
-
-    /**
-     * Construct a new hyperlink
-     *
-     * @param type the type of hyperlink to create
-     */
-    public HSSFHyperlink( int type )
-    {
-        this.link_type = type;
-        record = new HyperlinkRecord();
-        switch(type){
-            case LINK_URL:
-            case LINK_EMAIL:
-                record.newUrlLink();
-                break;
-            case LINK_FILE:
-                record.newFileLink();
-                break;
-            case LINK_DOCUMENT:
-                record.newDocumentLink();
-                break;
-        }
-    }
-
-    /**
-     * Initialize the hyperlink by a <code>HyperlinkRecord</code> record
-     *
-     * @param record
-     */
-    protected HSSFHyperlink( HyperlinkRecord record )
-    {
-        this.record = record;
-    }
-
-    /**
-     * Return the row of the first cell that contains the hyperlink
-     *
-     * @return the 0-based row of the cell that contains the hyperlink
-     */
-    public int getFirstRow(){
-        return record.getFirstRow();
-    }
-
-    /**
-     * Set the row of the first cell that contains the hyperlink
-     *
-     * @param row the 0-based row of the first cell that contains the hyperlink
-     */
-    public void setFirstRow(int row){
-        record.setFirstRow(row);
-    }
-
-    /**
-     * Return the row of the last cell that contains the hyperlink
-     *
-     * @return the 0-based row of the last cell that contains the hyperlink
-     */
-    public int getLastRow(){
-        return record.getLastRow();
-    }
-
-    /**
-     * Set the row of the last cell that contains the hyperlink
-     *
-     * @param row the 0-based row of the last cell that contains the hyperlink
-     */
-    public void setLastRow(int row){
-        record.setLastRow(row);
-    }
-
-    /**
-     * Return the column of the first cell that contains the hyperlink
-     *
-     * @return the 0-based column of the first cell that contains the hyperlink
-     */
-    public int getFirstColumn(){
-        return record.getFirstColumn();
-    }
-
-    /**
-     * Set the column of the first cell that contains the hyperlink
-     *
-     * @param col the 0-based column of the first cell that contains the hyperlink
-     */
-    public void setFirstColumn(int col){
-        record.setFirstColumn((short)col);
-    }
-
-    /**
-     * Return the column of the last cell that contains the hyperlink
-     *
-     * @return the 0-based column of the last cell that contains the hyperlink
-     */
-    public int getLastColumn(){
-        return record.getLastColumn();
-    }
-
-    /**
-     * Set the column of the last cell that contains the hyperlink
-     *
-     * @param col the 0-based column of the last cell that contains the hyperlink
-     */
-    public void setLastColumn(int col){
-        record.setLastColumn((short)col);
-    }
-
-    /**
-     * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.
-     *
-     * @return  the address of this hyperlink
-     */
-    public String getAddress(){
-        return record.getAddress();
-    }
-    public String getTextMark(){
-        return record.getTextMark();
-    }
-    public void setTextMark(String textMark) {
-        record.setTextMark(textMark);
-    }
-    public String getShortFilename(){
-        return record.getShortFilename();
-    }
-    public void setShortFilename(String shortFilename) {
-        record.setShortFilename(shortFilename);
-    }
-
-    /**
-     * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.
-     *
-     * @param address  the address of this hyperlink
-     */
-    public void setAddress(String address){
-        record.setAddress(address);
-    }
-
-    /**
-     * Return text label for this hyperlink
-     *
-     * @return  text to display
-     */
-    public String getLabel(){
-        return record.getLabel();
-    }
-
-    /**
-     * Sets text label for this hyperlink
-     *
-     * @param label text label for this hyperlink
-     */
-    public void setLabel(String label){
-        record.setLabel(label);
-    }
-
-    /**
-     * Return the type of this hyperlink
-     *
-     * @return the type of this hyperlink
-     */
-    public int getType(){
-        return link_type;
-    }
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hssf.usermodel;
+
+import org.apache.poi.hssf.record.HyperlinkRecord;
+import org.apache.poi.ss.usermodel.Hyperlink;
+
+/**
+ * Represents an Excel hyperlink.
+ *
+ * @author Yegor Kozlov (yegor at apache dot org)
+ */
+public class HSSFHyperlink implements Hyperlink {
+
+    /**
+     * Link to a existing file or web page
+     */
+    public static final int LINK_URL = 1;
+
+    /**
+     * Link to a place in this document
+     */
+    public static final int LINK_DOCUMENT = 2;
+
+    /**
+     * Link to an E-mail address
+     */
+    public static final int LINK_EMAIL = 3;
+
+    /**
+     * Link to a file
+     */
+    public static final int LINK_FILE = 4;
+
+    /**
+     * Low-level record object that stores the actual hyperlink data
+     */
+    protected HyperlinkRecord record = null;
+
+    /**
+     * If we create a new hypelrink remember its type
+     */
+    protected int link_type;
+
+    /**
+     * Construct a new hyperlink
+     *
+     * @param type the type of hyperlink to create
+     */
+    public HSSFHyperlink( int type )
+    {
+        this.link_type = type;
+        record = new HyperlinkRecord();
+        switch(type){
+            case LINK_URL:
+            case LINK_EMAIL:
+                record.newUrlLink();
+                break;
+            case LINK_FILE:
+                record.newFileLink();
+                break;
+            case LINK_DOCUMENT:
+                record.newDocumentLink();
+                break;
+        }
+    }
+
+    /**
+     * Initialize the hyperlink by a <code>HyperlinkRecord</code> record
+     *
+     * @param record
+     */
+    protected HSSFHyperlink( HyperlinkRecord record )
+    {
+        this.record = record;
+    }
+
+    /**
+     * Return the row of the first cell that contains the hyperlink
+     *
+     * @return the 0-based row of the cell that contains the hyperlink
+     */
+    public int getFirstRow(){
+        return record.getFirstRow();
+    }
+
+    /**
+     * Set the row of the first cell that contains the hyperlink
+     *
+     * @param row the 0-based row of the first cell that contains the hyperlink
+     */
+    public void setFirstRow(int row){
+        record.setFirstRow(row);
+    }
+
+    /**
+     * Return the row of the last cell that contains the hyperlink
+     *
+     * @return the 0-based row of the last cell that contains the hyperlink
+     */
+    public int getLastRow(){
+        return record.getLastRow();
+    }
+
+    /**
+     * Set the row of the last cell that contains the hyperlink
+     *
+     * @param row the 0-based row of the last cell that contains the hyperlink
+     */
+    public void setLastRow(int row){
+        record.setLastRow(row);
+    }
+
+    /**
+     * Return the column of the first cell that contains the hyperlink
+     *
+     * @return the 0-based column of the first cell that contains the hyperlink
+     */
+    public int getFirstColumn(){
+        return record.getFirstColumn();
+    }
+
+    /**
+     * Set the column of the first cell that contains the hyperlink
+     *
+     * @param col the 0-based column of the first cell that contains the hyperlink
+     */
+    public void setFirstColumn(int col){
+        record.setFirstColumn((short)col);
+    }
+
+    /**
+     * Return the column of the last cell that contains the hyperlink
+     *
+     * @return the 0-based column of the last cell that contains the hyperlink
+     */
+    public int getLastColumn(){
+        return record.getLastColumn();
+    }
+
+    /**
+     * Set the column of the last cell that contains the hyperlink
+     *
+     * @param col the 0-based column of the last cell that contains the hyperlink
+     */
+    public void setLastColumn(int col){
+        record.setLastColumn((short)col);
+    }
+
+    /**
+     * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.
+     *
+     * @return  the address of this hyperlink
+     */
+    public String getAddress(){
+        return record.getAddress();
+    }
+    public String getTextMark(){
+        return record.getTextMark();
+    }
+    public void setTextMark(String textMark) {
+        record.setTextMark(textMark);
+    }
+    public String getShortFilename(){
+        return record.getShortFilename();
+    }
+    public void setShortFilename(String shortFilename) {
+        record.setShortFilename(shortFilename);
+    }
+
+    /**
+     * Hypelink address. Depending on the hyperlink type it can be URL, e-mail, patrh to a file, etc.
+     *
+     * @param address  the address of this hyperlink
+     */
+    public void setAddress(String address){
+        record.setAddress(address);
+    }
+
+    /**
+     * Return text label for this hyperlink
+     *
+     * @return  text to display
+     */
+    public String getLabel(){
+        return record.getLabel();
+    }
+
+    /**
+     * Sets text label for this hyperlink
+     *
+     * @param label text label for this hyperlink
+     */
+    public void setLabel(String label){
+        record.setLabel(label);
+    }
+
+    /**
+     * Return the type of this hyperlink
+     *
+     * @return the type of this hyperlink
+     */
+    public int getType(){
+        return link_type;
+    }
+}

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java Tue May 19 16:29:51 2009
@@ -1,194 +1,193 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.usermodel;
-
-import org.apache.poi.hssf.model.Sheet;
-import org.apache.poi.hssf.record.CFRuleRecord;
-import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
-import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
-import org.apache.poi.ss.util.Region;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.SpreadsheetVersion;
-
-/**
- * The 'Conditional Formatting' facet of <tt>HSSFSheet</tt>
- * 
- * @author Dmitriy Kumshayev
- */
-public final class HSSFSheetConditionalFormatting {
-	
-    private final HSSFSheet _sheet;
-	private final ConditionalFormattingTable _conditionalFormattingTable;
-
-    /* package */ HSSFSheetConditionalFormatting(HSSFSheet sheet) {
-        _sheet = sheet;
-        _conditionalFormattingTable = sheet.getSheet().getConditionalFormattingTable();
-    }
-
-	/**
-	 * A factory method allowing to create a conditional formatting rule
-	 * with a cell comparison operator<p/>
-	 * TODO - formulas containing cell references are currently not parsed properly 
-	 *
-	 * @param comparisonOperation - a constant value from
-	 *		 <tt>{@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator}</tt>: <p>
-	 * <ul>
-	 *		 <li>BETWEEN</li>
-	 *		 <li>NOT_BETWEEN</li>
-	 *		 <li>EQUAL</li>
-	 *		 <li>NOT_EQUAL</li>
-	 *		 <li>GT</li>
-	 *		 <li>LT</li>
-	 *		 <li>GE</li>
-	 *		 <li>LE</li>
-	 * </ul>
-	 * </p>
-	 * @param formula1 - formula for the valued, compared with the cell
-	 * @param formula2 - second formula (only used with
-	 * {@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator#BETWEEN}) and
-	 * {@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator#NOT_BETWEEN} operations)
-	 */
-	public HSSFConditionalFormattingRule createConditionalFormattingRule(
-			byte comparisonOperation,
-			String formula1,
-			String formula2) {
-
-		HSSFWorkbook wb = _sheet.getWorkbook();
-		CFRuleRecord rr = CFRuleRecord.create(_sheet, comparisonOperation, formula1, formula2);
-		return new HSSFConditionalFormattingRule(wb, rr);
-	}
-
-	/**
-	 * A factory method allowing to create a conditional formatting rule with a formula.<br>
-	 *
-	 * The formatting rules are applied by Excel when the value of the formula not equal to 0.<p/>
-	 * TODO - formulas containing cell references are currently not parsed properly
-	 * @param formula - formula for the valued, compared with the cell
-	 */
-	public HSSFConditionalFormattingRule createConditionalFormattingRule(String formula) {
-        HSSFWorkbook wb = _sheet.getWorkbook();
-		CFRuleRecord rr = CFRuleRecord.create(_sheet, formula);
-		return new HSSFConditionalFormattingRule(wb, rr);
-	}
-
-	/**
-	 * Adds a copy of HSSFConditionalFormatting object to the sheet
-	 * <p>This method could be used to copy HSSFConditionalFormatting object
-	 * from one sheet to another. For example:
-	 * <pre>
-	 * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
-	 * newSheet.addConditionalFormatting(cf);
-	 * </pre>
-	 *
-	 * @param cf HSSFConditionalFormatting object
-	 * @return index of the new Conditional Formatting object
-	 */
-	public int addConditionalFormatting( HSSFConditionalFormatting cf ) {
-		CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
-
-		return _conditionalFormattingTable.add(cfraClone);
-	}
-	/**
-	 * @deprecated use <tt>CellRangeAddress</tt> instead of <tt>Region</tt>
-	 */
-	public int addConditionalFormatting(Region[] regions, HSSFConditionalFormattingRule[] cfRules) {
-		return addConditionalFormatting(Region.convertRegionsToCellRanges(regions), cfRules);
-	}
-	/**
-	 * Allows to add a new Conditional Formatting set to the sheet.
-	 *
-	 * @param regions - list of rectangular regions to apply conditional formatting rules
-	 * @param cfRules - set of up to three conditional formatting rules
-	 *
-	 * @return index of the newly created Conditional Formatting object
-	 */
-	public int addConditionalFormatting(CellRangeAddress[] regions, HSSFConditionalFormattingRule[] cfRules) {
-		if (regions == null) {
-			throw new IllegalArgumentException("regions must not be null");
-		}
-        for(CellRangeAddress range : regions) range.validate(SpreadsheetVersion.EXCEL97);
-
-        if (cfRules == null) {
-			throw new IllegalArgumentException("cfRules must not be null");
-		}
-		if (cfRules.length == 0) {
-			throw new IllegalArgumentException("cfRules must not be empty");
-		}
-		if (cfRules.length > 3) {
-			throw new IllegalArgumentException("Number of rules must not exceed 3");
-		}
-
-		CFRuleRecord[] rules = new CFRuleRecord[cfRules.length];
-		for (int i = 0; i != cfRules.length; i++) {
-			rules[i] = cfRules[i].getCfRuleRecord();
-		}
-		CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
-		return _conditionalFormattingTable.add(cfra);
-	}
-
-	public int addConditionalFormatting(CellRangeAddress[] regions,
-			HSSFConditionalFormattingRule rule1)
-	{
-		return addConditionalFormatting(regions,
-				new HSSFConditionalFormattingRule[]
-				{
-					rule1
-				});
-	}
-
-	public int addConditionalFormatting(CellRangeAddress[] regions,
-			HSSFConditionalFormattingRule rule1,
-			HSSFConditionalFormattingRule rule2)
-	{
-		return addConditionalFormatting(regions,
-				new HSSFConditionalFormattingRule[]
-				{
-						rule1, rule2
-				});
-	}
-
-	/**
-	* gets Conditional Formatting object at a particular index
-	* 
-	* @param index
-	*			of the Conditional Formatting object to fetch
-	* @return Conditional Formatting object
-	*/
-	public HSSFConditionalFormatting getConditionalFormattingAt(int index) {
-		CFRecordsAggregate cf = _conditionalFormattingTable.get(index);
-		if (cf == null) {
-			return null;
-		}
-		return new HSSFConditionalFormatting(_sheet.getWorkbook(), cf);
-	}
-
-	/**
-	* @return number of Conditional Formatting objects of the sheet
-	*/
-	public int getNumConditionalFormattings() {
-		return _conditionalFormattingTable.size();
-	}
-
-	/**
-	* removes a Conditional Formatting object by index
-	* @param index of a Conditional Formatting object to remove
-	*/
-	public void removeConditionalFormatting(int index) {
-		_conditionalFormattingTable.remove(index);
-	}
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.usermodel;
+
+import org.apache.poi.hssf.record.CFRuleRecord;
+import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
+import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
+import org.apache.poi.ss.util.Region;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.SpreadsheetVersion;
+
+/**
+ * The 'Conditional Formatting' facet of <tt>HSSFSheet</tt>
+ *
+ * @author Dmitriy Kumshayev
+ */
+public final class HSSFSheetConditionalFormatting {
+
+	private final HSSFSheet _sheet;
+	private final ConditionalFormattingTable _conditionalFormattingTable;
+
+	/* package */ HSSFSheetConditionalFormatting(HSSFSheet sheet) {
+		_sheet = sheet;
+		_conditionalFormattingTable = sheet.getSheet().getConditionalFormattingTable();
+	}
+
+	/**
+	 * A factory method allowing to create a conditional formatting rule
+	 * with a cell comparison operator<p/>
+	 * TODO - formulas containing cell references are currently not parsed properly
+	 *
+	 * @param comparisonOperation - a constant value from
+	 *		 <tt>{@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator}</tt>: <p>
+	 * <ul>
+	 *		 <li>BETWEEN</li>
+	 *		 <li>NOT_BETWEEN</li>
+	 *		 <li>EQUAL</li>
+	 *		 <li>NOT_EQUAL</li>
+	 *		 <li>GT</li>
+	 *		 <li>LT</li>
+	 *		 <li>GE</li>
+	 *		 <li>LE</li>
+	 * </ul>
+	 * </p>
+	 * @param formula1 - formula for the valued, compared with the cell
+	 * @param formula2 - second formula (only used with
+	 * {@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator#BETWEEN}) and
+	 * {@link org.apache.poi.hssf.record.CFRuleRecord.ComparisonOperator#NOT_BETWEEN} operations)
+	 */
+	public HSSFConditionalFormattingRule createConditionalFormattingRule(
+			byte comparisonOperation,
+			String formula1,
+			String formula2) {
+
+		HSSFWorkbook wb = _sheet.getWorkbook();
+		CFRuleRecord rr = CFRuleRecord.create(_sheet, comparisonOperation, formula1, formula2);
+		return new HSSFConditionalFormattingRule(wb, rr);
+	}
+
+	/**
+	 * A factory method allowing to create a conditional formatting rule with a formula.<br>
+	 *
+	 * The formatting rules are applied by Excel when the value of the formula not equal to 0.<p/>
+	 * TODO - formulas containing cell references are currently not parsed properly
+	 * @param formula - formula for the valued, compared with the cell
+	 */
+	public HSSFConditionalFormattingRule createConditionalFormattingRule(String formula) {
+		HSSFWorkbook wb = _sheet.getWorkbook();
+		CFRuleRecord rr = CFRuleRecord.create(_sheet, formula);
+		return new HSSFConditionalFormattingRule(wb, rr);
+	}
+
+	/**
+	 * Adds a copy of HSSFConditionalFormatting object to the sheet
+	 * <p>This method could be used to copy HSSFConditionalFormatting object
+	 * from one sheet to another. For example:
+	 * <pre>
+	 * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
+	 * newSheet.addConditionalFormatting(cf);
+	 * </pre>
+	 *
+	 * @param cf HSSFConditionalFormatting object
+	 * @return index of the new Conditional Formatting object
+	 */
+	public int addConditionalFormatting( HSSFConditionalFormatting cf ) {
+		CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
+
+		return _conditionalFormattingTable.add(cfraClone);
+	}
+	/**
+	 * @deprecated use <tt>CellRangeAddress</tt> instead of <tt>Region</tt>
+	 */
+	public int addConditionalFormatting(Region[] regions, HSSFConditionalFormattingRule[] cfRules) {
+		return addConditionalFormatting(Region.convertRegionsToCellRanges(regions), cfRules);
+	}
+	/**
+	 * Allows to add a new Conditional Formatting set to the sheet.
+	 *
+	 * @param regions - list of rectangular regions to apply conditional formatting rules
+	 * @param cfRules - set of up to three conditional formatting rules
+	 *
+	 * @return index of the newly created Conditional Formatting object
+	 */
+	public int addConditionalFormatting(CellRangeAddress[] regions, HSSFConditionalFormattingRule[] cfRules) {
+		if (regions == null) {
+			throw new IllegalArgumentException("regions must not be null");
+		}
+		for(CellRangeAddress range : regions) range.validate(SpreadsheetVersion.EXCEL97);
+
+		if (cfRules == null) {
+			throw new IllegalArgumentException("cfRules must not be null");
+		}
+		if (cfRules.length == 0) {
+			throw new IllegalArgumentException("cfRules must not be empty");
+		}
+		if (cfRules.length > 3) {
+			throw new IllegalArgumentException("Number of rules must not exceed 3");
+		}
+
+		CFRuleRecord[] rules = new CFRuleRecord[cfRules.length];
+		for (int i = 0; i != cfRules.length; i++) {
+			rules[i] = cfRules[i].getCfRuleRecord();
+		}
+		CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
+		return _conditionalFormattingTable.add(cfra);
+	}
+
+	public int addConditionalFormatting(CellRangeAddress[] regions,
+			HSSFConditionalFormattingRule rule1)
+	{
+		return addConditionalFormatting(regions,
+				new HSSFConditionalFormattingRule[]
+				{
+					rule1
+				});
+	}
+
+	public int addConditionalFormatting(CellRangeAddress[] regions,
+			HSSFConditionalFormattingRule rule1,
+			HSSFConditionalFormattingRule rule2)
+	{
+		return addConditionalFormatting(regions,
+				new HSSFConditionalFormattingRule[]
+				{
+						rule1, rule2
+				});
+	}
+
+	/**
+	* gets Conditional Formatting object at a particular index
+	*
+	* @param index
+	*			of the Conditional Formatting object to fetch
+	* @return Conditional Formatting object
+	*/
+	public HSSFConditionalFormatting getConditionalFormattingAt(int index) {
+		CFRecordsAggregate cf = _conditionalFormattingTable.get(index);
+		if (cf == null) {
+			return null;
+		}
+		return new HSSFConditionalFormatting(_sheet.getWorkbook(), cf);
+	}
+
+	/**
+	* @return number of Conditional Formatting objects of the sheet
+	*/
+	public int getNumConditionalFormattings() {
+		return _conditionalFormattingTable.size();
+	}
+
+	/**
+	* removes a Conditional Formatting object by index
+	* @param index of a Conditional Formatting object to remove
+	*/
+	public void removeConditionalFormatting(int index) {
+		_conditionalFormattingTable.remove(index);
+	}
+}

Modified: poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddress.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddress.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddress.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddress.java Tue May 19 16:29:51 2009
@@ -1,38 +1,38 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.util;
-
-import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.hssf.record.SelectionRecord;
-
-/**
- * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address'<p/>
- * 
- * Note - {@link SelectionRecord} uses the BIFF5 version of this structure
- * @deprecated use {@link org.apache.poi.ss.util.CellRangeAddress}
- * @author Dragos Buleandra (dragos.buleandra@trade2b.ro)
- */
-public class CellRangeAddress extends org.apache.poi.ss.util.CellRangeAddress {
-
-	public CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol) {
-		super(firstRow, lastRow, firstCol, lastCol);
-	}
-	public CellRangeAddress(RecordInputStream in) {
-		super(in);
-	}
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.util;
+
+import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.record.SelectionRecord;
+
+/**
+ * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address'<p/>
+ *
+ * Note - {@link SelectionRecord} uses the BIFF5 version of this structure
+ * @deprecated use {@link org.apache.poi.ss.util.CellRangeAddress}
+ * @author Dragos Buleandra (dragos.buleandra@trade2b.ro)
+ */
+public class CellRangeAddress extends org.apache.poi.ss.util.CellRangeAddress {
+
+	public CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol) {
+		super(firstRow, lastRow, firstCol, lastCol);
+	}
+	public CellRangeAddress(RecordInputStream in) {
+		super(in);
+	}
+}

Modified: poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddress8Bit.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddress8Bit.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddress8Bit.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/util/CellRangeAddress8Bit.java Tue May 19 16:29:51 2009
@@ -1,73 +1,73 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.hssf.util;
-
-import org.apache.poi.ss.util.CellRangeAddressBase;
-import org.apache.poi.util.LittleEndianByteArrayOutputStream;
-import org.apache.poi.util.LittleEndianInput;
-import org.apache.poi.util.LittleEndianOutput;
-
-/**
- * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address'<p/>
- * 
- * Like {@link CellRangeAddress} except column fields are 8-bit.
- * 
- * @author Josh Micich
- */
-public final class CellRangeAddress8Bit extends CellRangeAddressBase {
-
-	public static final int ENCODED_SIZE = 6;
-
-	public CellRangeAddress8Bit(int firstRow, int lastRow, int firstCol, int lastCol) {
-		super(firstRow, lastRow, firstCol, lastCol);
-	}
-
-	public CellRangeAddress8Bit(LittleEndianInput in) {
-		super(readUShortAndCheck(in), in.readUShort(), in.readUByte(), in.readUByte());
-	}
-
-	private static int readUShortAndCheck(LittleEndianInput in) {
-		if (in.available() < ENCODED_SIZE) {
-			// Ran out of data
-			throw new RuntimeException("Ran out of data reading CellRangeAddress");
-		}
-		return in.readUShort();
-	}
-
-	/**
-	 * @deprecated use {@link #serialize(LittleEndianOutput)}
-	 */
-	public int serialize(int offset, byte[] data) {
-		serialize(new LittleEndianByteArrayOutputStream(data, offset, ENCODED_SIZE));
-		return ENCODED_SIZE;
-	}
-	public void serialize(LittleEndianOutput out) {
-		out.writeShort(getFirstRow());
-		out.writeShort(getLastRow());
-		out.writeByte(getFirstColumn());
-		out.writeByte(getLastColumn());
-	}
-	
-	public CellRangeAddress8Bit copy() {
-		return new CellRangeAddress8Bit(getFirstRow(), getLastRow(), getFirstColumn(), getLastColumn());
-	}
-
-	public static int getEncodedSize(int numberOfItems) {
-		return numberOfItems * ENCODED_SIZE;
-	}
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.util;
+
+import org.apache.poi.ss.util.CellRangeAddressBase;
+import org.apache.poi.util.LittleEndianByteArrayOutputStream;
+import org.apache.poi.util.LittleEndianInput;
+import org.apache.poi.util.LittleEndianOutput;
+
+/**
+ * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address'<p/>
+ *
+ * Like {@link CellRangeAddress} except column fields are 8-bit.
+ *
+ * @author Josh Micich
+ */
+public final class CellRangeAddress8Bit extends CellRangeAddressBase {
+
+	public static final int ENCODED_SIZE = 6;
+
+	public CellRangeAddress8Bit(int firstRow, int lastRow, int firstCol, int lastCol) {
+		super(firstRow, lastRow, firstCol, lastCol);
+	}
+
+	public CellRangeAddress8Bit(LittleEndianInput in) {
+		super(readUShortAndCheck(in), in.readUShort(), in.readUByte(), in.readUByte());
+	}
+
+	private static int readUShortAndCheck(LittleEndianInput in) {
+		if (in.available() < ENCODED_SIZE) {
+			// Ran out of data
+			throw new RuntimeException("Ran out of data reading CellRangeAddress");
+		}
+		return in.readUShort();
+	}
+
+	/**
+	 * @deprecated use {@link #serialize(LittleEndianOutput)}
+	 */
+	public int serialize(int offset, byte[] data) {
+		serialize(new LittleEndianByteArrayOutputStream(data, offset, ENCODED_SIZE));
+		return ENCODED_SIZE;
+	}
+	public void serialize(LittleEndianOutput out) {
+		out.writeShort(getFirstRow());
+		out.writeShort(getLastRow());
+		out.writeByte(getFirstColumn());
+		out.writeByte(getLastColumn());
+	}
+
+	public CellRangeAddress8Bit copy() {
+		return new CellRangeAddress8Bit(getFirstRow(), getLastRow(), getFirstColumn(), getLastColumn());
+	}
+
+	public static int getEncodedSize(int numberOfItems) {
+		return numberOfItems * ENCODED_SIZE;
+	}
+}

Modified: poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSDump.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSDump.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/dev/POIFSDump.java Tue May 19 16:29:51 2009
@@ -1,74 +1,74 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-package org.apache.poi.poifs.dev;
-
-import org.apache.poi.poifs.filesystem.*;
-
-import java.io.FileInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.FileOutputStream;
-import java.util.Iterator;
-
-/**
- *
- * Dump internal structure of a OLE2 file into file system
- *
- * @author Yegor Kozlov
- */
-public class POIFSDump {
-
-    public static void main(String[] args) throws Exception {
-        for (int i = 0; i < args.length; i++) {
-            System.out.println("Dumping " + args[i]);
-            FileInputStream is = new FileInputStream(args[i]);
-            POIFSFileSystem fs = new POIFSFileSystem(is);
-            is.close();
-
-            DirectoryEntry root = fs.getRoot();
-            File file = new File(root.getName());
-            file.mkdir();
-
-            dump(root, file);
-        }
-   }
-
-
-    public static void dump(DirectoryEntry root, File parent) throws IOException {
-        for(Iterator it = root.getEntries(); it.hasNext();){
-            Entry entry = (Entry)it.next();
-            if(entry instanceof DocumentNode){
-                DocumentNode node = (DocumentNode)entry;
-                DocumentInputStream is = new DocumentInputStream(node);
-                byte[] bytes = new byte[node.getSize()];
-                is.read(bytes);
-                is.close();
-
-                FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim()));
-                out.write(bytes);
-                out.close();
-            } else if (entry instanceof DirectoryEntry){
-                DirectoryEntry dir = (DirectoryEntry)entry;
-                File file = new File(parent, entry.getName());
-                file.mkdir();
-                dump(dir, file);
-            } else {
-                System.err.println("Skipping unsupported POIFS entry: " + entry);
-            }
-        }
-    }
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.poifs.dev;
+
+import org.apache.poi.poifs.filesystem.*;
+
+import java.io.FileInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.util.Iterator;
+
+/**
+ *
+ * Dump internal structure of a OLE2 file into file system
+ *
+ * @author Yegor Kozlov
+ */
+public class POIFSDump {
+
+    public static void main(String[] args) throws Exception {
+        for (int i = 0; i < args.length; i++) {
+            System.out.println("Dumping " + args[i]);
+            FileInputStream is = new FileInputStream(args[i]);
+            POIFSFileSystem fs = new POIFSFileSystem(is);
+            is.close();
+
+            DirectoryEntry root = fs.getRoot();
+            File file = new File(root.getName());
+            file.mkdir();
+
+            dump(root, file);
+        }
+   }
+
+
+    public static void dump(DirectoryEntry root, File parent) throws IOException {
+        for(Iterator it = root.getEntries(); it.hasNext();){
+            Entry entry = (Entry)it.next();
+            if(entry instanceof DocumentNode){
+                DocumentNode node = (DocumentNode)entry;
+                DocumentInputStream is = new DocumentInputStream(node);
+                byte[] bytes = new byte[node.getSize()];
+                is.read(bytes);
+                is.close();
+
+                FileOutputStream out = new FileOutputStream(new File(parent, node.getName().trim()));
+                out.write(bytes);
+                out.close();
+            } else if (entry instanceof DirectoryEntry){
+                DirectoryEntry dir = (DirectoryEntry)entry;
+                File file = new File(parent, entry.getName());
+                file.mkdir();
+                dump(dir, file);
+            } else {
+                System.err.println("Skipping unsupported POIFS entry: " + entry);
+            }
+        }
+    }
+}

Modified: poi/trunk/src/java/org/apache/poi/ss/SpreadsheetVersion.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/SpreadsheetVersion.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/SpreadsheetVersion.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/SpreadsheetVersion.java Tue May 19 16:29:51 2009
@@ -1,120 +1,119 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss;
-
-import org.apache.poi.ss.util.CellReference;
-
-/**
- * This enum allows spreadsheets from multiple Excel versions to be handled by the common code.
- * Properties of this enum correspond to attributes of the <i>spreadsheet</i> that are easily
- * discernable to the user.  It is not intended to deal with low-level issues like file formats.  
- * <p/>
- * 
- * @author Josh Micich
- * @author Yegor Kozlov
- */
-public enum SpreadsheetVersion {
-    /**
-     * Excel97 format aka BIFF8
-     * <ul>
-     * <li>The total number of available columns is 256 (2^8)</li>
-     * <li>The total number of available rows is 64k (2^16)</li>
-     * <li>The maximum number of arguments to a function is 30</li>
-     * <li>Number of conditional format conditions on a cell is 3</li>
-     * </ul>
-     */
-	EXCEL97(0x10000, 0x0100, 30, 3),
-
-    /**
-     * Excel2007
-     *
-     * <ul>
-     * <li>The total number of available columns is 16K (2^14)</li>
-     * <li>The total number of available rows is 1M (2^20)</li>
-     * <li>The maximum number of arguments to a function is 255</li>
-     * <li>Number of conditional format conditions on a cell is unlimited
-     *  (actually limited by available memory in Excel)</li>
-     * <ul>
-     */
-    EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE);
-
-	private final int _maxRows;
-	private final int _maxColumns;
-	private final int _maxFunctionArgs;
-    private final int _maxCondFormats;
-
-	private SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats) {
-		_maxRows = maxRows;
-		_maxColumns = maxColumns;
-		_maxFunctionArgs = maxFunctionArgs;
-        _maxCondFormats = maxCondFormats;
-	}
-
-	/**
-	 * @return the maximum number of usable rows in each spreadsheet
-	 */
-	public int getMaxRows() {
-		return _maxRows;
-	}
-
-    /**
-     * @return the last (maximum) valid row index, equals to <code> getMaxRows() - 1 </code>
-     */
-    public int getLastRowIndex() {
-        return _maxRows - 1;
-    }
-
-	/**
-	 * @return the maximum number of usable columns in each spreadsheet
-	 */
-	public int getMaxColumns() {
-		return _maxColumns;
-	}
-
-    /**
-     * @return the last (maximum) valid column index, equals to <code> getMaxColumns() - 1 </code>
-     */
-    public int getLastColumnIndex() {
-        return _maxColumns - 1;
-    }
-
-	/**
-	 * @return the maximum number arguments that can be passed to a multi-arg
-	 *         function (e.g. COUNTIF)
-	 */
-	public int getMaxFunctionArgs() {
-		return _maxFunctionArgs;
-	}
-
-    /**
-     *
-     * @return the maximum number of conditional format conditions on a cell
-     */
-    public int getMaxConditionalFormats() {
-        return _maxCondFormats;
-    }
-
-    /**
-     * 
-     * @return the last valid column index in a ALPHA-26 representation
-     *   ( <code>IV</code> or <code>XFD</code>).
-     */
-    public String getLastColumnName() {
-        return CellReference.convertNumToColString(getLastColumnIndex());
-    }
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss;
+
+import org.apache.poi.ss.util.CellReference;
+
+/**
+ * This enum allows spreadsheets from multiple Excel versions to be handled by the common code.
+ * Properties of this enum correspond to attributes of the <i>spreadsheet</i> that are easily
+ * discernable to the user.  It is not intended to deal with low-level issues like file formats.
+ * <p/>
+ *
+ * @author Josh Micich
+ * @author Yegor Kozlov
+ */
+public enum SpreadsheetVersion {
+	/**
+	 * Excel97 format aka BIFF8
+	 * <ul>
+	 * <li>The total number of available columns is 256 (2^8)</li>
+	 * <li>The total number of available rows is 64k (2^16)</li>
+	 * <li>The maximum number of arguments to a function is 30</li>
+	 * <li>Number of conditional format conditions on a cell is 3</li>
+	 * </ul>
+	 */
+	EXCEL97(0x10000, 0x0100, 30, 3),
+
+	/**
+	 * Excel2007
+	 *
+	 * <ul>
+	 * <li>The total number of available columns is 16K (2^14)</li>
+	 * <li>The total number of available rows is 1M (2^20)</li>
+	 * <li>The maximum number of arguments to a function is 255</li>
+	 * <li>Number of conditional format conditions on a cell is unlimited
+	 * (actually limited by available memory in Excel)</li>
+	 * <ul>
+	 */
+	EXCEL2007(0x100000, 0x4000, 255, Integer.MAX_VALUE);
+
+	private final int _maxRows;
+	private final int _maxColumns;
+	private final int _maxFunctionArgs;
+	private final int _maxCondFormats;
+
+	private SpreadsheetVersion(int maxRows, int maxColumns, int maxFunctionArgs, int maxCondFormats) {
+		_maxRows = maxRows;
+		_maxColumns = maxColumns;
+		_maxFunctionArgs = maxFunctionArgs;
+		_maxCondFormats = maxCondFormats;
+	}
+
+	/**
+	 * @return the maximum number of usable rows in each spreadsheet
+	 */
+	public int getMaxRows() {
+		return _maxRows;
+	}
+
+	/**
+	 * @return the last (maximum) valid row index, equals to <code> getMaxRows() - 1 </code>
+	 */
+	public int getLastRowIndex() {
+		return _maxRows - 1;
+	}
+
+	/**
+	 * @return the maximum number of usable columns in each spreadsheet
+	 */
+	public int getMaxColumns() {
+		return _maxColumns;
+	}
+
+	/**
+	 * @return the last (maximum) valid column index, equals to <code> getMaxColumns() - 1 </code>
+	 */
+	public int getLastColumnIndex() {
+		return _maxColumns - 1;
+	}
+
+	/**
+	 * @return the maximum number arguments that can be passed to a multi-arg function (e.g. COUNTIF)
+	 */
+	public int getMaxFunctionArgs() {
+		return _maxFunctionArgs;
+	}
+
+	/**
+	 *
+	 * @return the maximum number of conditional format conditions on a cell
+	 */
+	public int getMaxConditionalFormats() {
+		return _maxCondFormats;
+	}
+
+	/**
+	 *
+	 * @return the last valid column index in a ALPHA-26 representation
+	 *  (<code>IV</code> or <code>XFD</code>).
+	 */
+	public String getLastColumnName() {
+		return CellReference.convertNumToColString(getLastColumnIndex());
+	}
+}

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/CellEvaluationFrame.java Tue May 19 16:29:51 2009
@@ -1,77 +1,77 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.poi.hssf.record.formula.eval.ValueEval;
-
-/**
- * Stores details about the current evaluation of a cell.<br/>
- */
-final class CellEvaluationFrame {
-
-	private final FormulaCellCacheEntry _cce;
-	private final Set<CellCacheEntry> _sensitiveInputCells;
-	private FormulaUsedBlankCellSet _usedBlankCellGroup;
-
-	public CellEvaluationFrame(FormulaCellCacheEntry cce) {
-		_cce = cce;
-		_sensitiveInputCells = new HashSet<CellCacheEntry>();
-	}
-	public CellCacheEntry getCCE() {
-		return _cce;
-	}
-
-	public String toString() {
-		StringBuffer sb = new StringBuffer(64);
-		sb.append(getClass().getName()).append(" [");
-		sb.append("]");
-		return sb.toString();
-	}
-	/**
-	 * @param inputCell a cell directly used by the formula of this evaluation frame
-	 */
-	public void addSensitiveInputCell(CellCacheEntry inputCell) {
-		_sensitiveInputCells.add(inputCell);
-	}
-	/**
-	 * @return never <code>null</code>, (possibly empty) array of all cells directly used while 
-	 * evaluating the formula of this frame.
-	 */
-	private CellCacheEntry[] getSensitiveInputCells() {
-		int nItems = _sensitiveInputCells.size();
-		if (nItems < 1) {
-			return CellCacheEntry.EMPTY_ARRAY;
-		}
-		CellCacheEntry[] result = new CellCacheEntry[nItems];
-		_sensitiveInputCells.toArray(result);
-		return result;
-	}
-	public void addUsedBlankCell(int bookIndex, int sheetIndex, int rowIndex, int columnIndex) {
-		if (_usedBlankCellGroup == null) {
-			_usedBlankCellGroup = new FormulaUsedBlankCellSet();
-		}
-		_usedBlankCellGroup.addCell(bookIndex, sheetIndex, rowIndex, columnIndex);
-	}
-	
-	public void updateFormulaResult(ValueEval result) {
-		_cce.updateFormulaResult(result, getSensitiveInputCells(), _usedBlankCellGroup);
-	}
-}
\ No newline at end of file
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
+
+/**
+ * Stores details about the current evaluation of a cell.<br/>
+ */
+final class CellEvaluationFrame {
+
+	private final FormulaCellCacheEntry _cce;
+	private final Set<CellCacheEntry> _sensitiveInputCells;
+	private FormulaUsedBlankCellSet _usedBlankCellGroup;
+
+	public CellEvaluationFrame(FormulaCellCacheEntry cce) {
+		_cce = cce;
+		_sensitiveInputCells = new HashSet<CellCacheEntry>();
+	}
+	public CellCacheEntry getCCE() {
+		return _cce;
+	}
+
+	public String toString() {
+		StringBuffer sb = new StringBuffer(64);
+		sb.append(getClass().getName()).append(" [");
+		sb.append("]");
+		return sb.toString();
+	}
+	/**
+	 * @param inputCell a cell directly used by the formula of this evaluation frame
+	 */
+	public void addSensitiveInputCell(CellCacheEntry inputCell) {
+		_sensitiveInputCells.add(inputCell);
+	}
+	/**
+	 * @return never <code>null</code>, (possibly empty) array of all cells directly used while
+	 * evaluating the formula of this frame.
+	 */
+	private CellCacheEntry[] getSensitiveInputCells() {
+		int nItems = _sensitiveInputCells.size();
+		if (nItems < 1) {
+			return CellCacheEntry.EMPTY_ARRAY;
+		}
+		CellCacheEntry[] result = new CellCacheEntry[nItems];
+		_sensitiveInputCells.toArray(result);
+		return result;
+	}
+	public void addUsedBlankCell(int bookIndex, int sheetIndex, int rowIndex, int columnIndex) {
+		if (_usedBlankCellGroup == null) {
+			_usedBlankCellGroup = new FormulaUsedBlankCellSet();
+		}
+		_usedBlankCellGroup.addCell(bookIndex, sheetIndex, rowIndex, columnIndex);
+	}
+
+	public void updateFormulaResult(ValueEval result) {
+		_cce.updateFormulaResult(result, getSensitiveInputCells(), _usedBlankCellGroup);
+	}
+}

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationName.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationName.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationName.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationName.java Tue May 19 16:29:51 2009
@@ -1,41 +1,41 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-import org.apache.poi.hssf.record.formula.NamePtg;
-import org.apache.poi.hssf.record.formula.Ptg;
-/**
- * Abstracts a name record for formula evaluation.<br/>
- * 
- * For POI internal use only
- * 
- * @author Josh Micich
- */
-public interface EvaluationName {
-
-	String getNameText();
-
-	boolean isFunctionName();
-
-	boolean hasFormula();
-
-	Ptg[] getNameDefinition();
-
-	boolean isRange();
-	NamePtg createPtg();
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula;
+
+import org.apache.poi.hssf.record.formula.NamePtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+/**
+ * Abstracts a name record for formula evaluation.<br/>
+ *
+ * For POI internal use only
+ *
+ * @author Josh Micich
+ */
+public interface EvaluationName {
+
+	String getNameText();
+
+	boolean isFunctionName();
+
+	boolean hasFormula();
+
+	Ptg[] getNameDefinition();
+
+	boolean isRange();
+	NamePtg createPtg();
+}

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java Tue May 19 16:29:51 2009
@@ -1,65 +1,65 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-import org.apache.poi.hssf.record.formula.NamePtg;
-import org.apache.poi.hssf.record.formula.NameXPtg;
-import org.apache.poi.hssf.record.formula.Ptg;
-
-/**
- * Abstracts a workbook for the purpose of formula evaluation.<br/>
- * 
- * For POI internal use only
- * 
- * @author Josh Micich
- */
-public interface EvaluationWorkbook {
-	String getSheetName(int sheetIndex);
-	/**
-	 * @return -1 if the specified sheet is from a different book
-	 */
-	int getSheetIndex(EvaluationSheet sheet);
-	int getSheetIndex(String sheetName);
-
-	EvaluationSheet getSheet(int sheetIndex);
-
-	/**
-	 * @return <code>null</code> if externSheetIndex refers to a sheet inside the current workbook
-	 */
-	ExternalSheet getExternalSheet(int externSheetIndex);
-	int convertFromExternSheetIndex(int externSheetIndex);
-	EvaluationName getName(NamePtg namePtg);
-	String resolveNameXText(NameXPtg ptg);
-	Ptg[] getFormulaTokens(EvaluationCell cell);
-	
-	class ExternalSheet {
-		private final String _workbookName;
-		private final String _sheetName;
-
-		public ExternalSheet(String workbookName, String sheetName) {
-			_workbookName = workbookName;
-			_sheetName = sheetName;
-		}
-		public String getWorkbookName() {
-			return _workbookName;
-		}
-		public String getSheetName() {
-			return _sheetName;
-		}
-	}
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula;
+
+import org.apache.poi.hssf.record.formula.NamePtg;
+import org.apache.poi.hssf.record.formula.NameXPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+
+/**
+ * Abstracts a workbook for the purpose of formula evaluation.<br/>
+ *
+ * For POI internal use only
+ *
+ * @author Josh Micich
+ */
+public interface EvaluationWorkbook {
+	String getSheetName(int sheetIndex);
+	/**
+	 * @return -1 if the specified sheet is from a different book
+	 */
+	int getSheetIndex(EvaluationSheet sheet);
+	int getSheetIndex(String sheetName);
+
+	EvaluationSheet getSheet(int sheetIndex);
+
+	/**
+	 * @return <code>null</code> if externSheetIndex refers to a sheet inside the current workbook
+	 */
+	ExternalSheet getExternalSheet(int externSheetIndex);
+	int convertFromExternSheetIndex(int externSheetIndex);
+	EvaluationName getName(NamePtg namePtg);
+	String resolveNameXText(NameXPtg ptg);
+	Ptg[] getFormulaTokens(EvaluationCell cell);
+
+	class ExternalSheet {
+		private final String _workbookName;
+		private final String _sheetName;
+
+		public ExternalSheet(String workbookName, String sheetName) {
+			_workbookName = workbookName;
+			_sheetName = sheetName;
+		}
+		public String getWorkbookName() {
+			return _workbookName;
+		}
+		public String getSheetName() {
+			return _sheetName;
+		}
+	}
+}

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/Formula.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/Formula.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/Formula.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/Formula.java Tue May 19 16:29:51 2009
@@ -1,197 +1,197 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-import java.util.Arrays;
-
-import org.apache.poi.hssf.record.ArrayRecord;
-import org.apache.poi.hssf.record.SharedFormulaRecord;
-import org.apache.poi.hssf.record.TableRecord;
-import org.apache.poi.hssf.record.formula.ExpPtg;
-import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.hssf.record.formula.TblPtg;
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.LittleEndianByteArrayInputStream;
-import org.apache.poi.util.LittleEndianInput;
-import org.apache.poi.util.LittleEndianOutput;
-
-/**
- * Encapsulates an encoded formula token array. 
- * 
- * @author Josh Micich
- */
-public class Formula {
-
-	private static final Formula EMPTY = new Formula(new byte[0], 0);
-
-	/** immutable */
-	private final byte[] _byteEncoding;
-	private final int _encodedTokenLen;
-	
-	private Formula(byte[] byteEncoding, int encodedTokenLen) {
-		_byteEncoding = byteEncoding;
-		_encodedTokenLen = encodedTokenLen;
-		if (false) { // set to true to eagerly check Ptg decoding 
-			LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);
-			Ptg.readTokens(encodedTokenLen, in);
-			int nUnusedBytes = _byteEncoding.length - in.getReadIndex();
-			if (nUnusedBytes > 0) {
-				// TODO - this seems to occur when IntersectionPtg is present
-				// This example file "IntersectionPtg.xls"
-				// used by test: TestIntersectionPtg.testReading()
-				// has 10 bytes unused at the end of the formula
-				// 10 extra bytes are just 0x01 and 0x00
-				System.out.println(nUnusedBytes + " unused bytes at end of formula");
-			}
-		}
-	}
-	/**
-	 * Convenience method for {@link #read(int, LittleEndianInput, int)}
-	 */
-	public static Formula read(int encodedTokenLen, LittleEndianInput in) {
-		return read(encodedTokenLen, in, encodedTokenLen);
-	}
-	/**
-	 * When there are no array constants present, <tt>encodedTokenLen</tt>==<tt>totalEncodedLen</tt>
-	 * @param encodedTokenLen number of bytes in the stream taken by the plain formula tokens
-	 * @param totalEncodedLen the total number of bytes in the formula (includes trailing encoding
-	 * for array constants, but does not include 2 bytes for initial <tt>ushort encodedTokenLen</tt> field.
-	 * @return A new formula object as read from the stream.  Possibly empty, never <code>null</code>.
-	 */
-	public static Formula read(int encodedTokenLen, LittleEndianInput in, int totalEncodedLen) {
-		byte[] byteEncoding = new byte[totalEncodedLen];
-		in.readFully(byteEncoding);
-		return new Formula(byteEncoding, encodedTokenLen);
-	}
-	
-	public Ptg[] getTokens() {
-		LittleEndianInput in = new LittleEndianByteArrayInputStream(_byteEncoding);
-		return Ptg.readTokens(_encodedTokenLen, in);
-	}
-	/**
-	 * Writes  The formula encoding is includes:
-	 * <ul>
-	 * <li>ushort tokenDataLen</li>
-	 * <li>tokenData</li>
-	 * <li>arrayConstantData (if present)</li>
-	 * </ul>
-	 */
-	public void serialize(LittleEndianOutput out) {
-		out.writeShort(_encodedTokenLen);
-		out.write(_byteEncoding);
-	}
-
-	public void serializeTokens(LittleEndianOutput out) {
-		out.write(_byteEncoding, 0, _encodedTokenLen);
-	}
-	public void serializeArrayConstantData(LittleEndianOutput out) {
-		int len = _byteEncoding.length-_encodedTokenLen;
-		out.write(_byteEncoding, _encodedTokenLen, len);
-	}
-	
-	
-	/**
-	 * @return total formula encoding length.  The formula encoding includes:
-	 * <ul>
-	 * <li>ushort tokenDataLen</li>
-	 * <li>tokenData</li>
-	 * <li>arrayConstantData (optional)</li>
-	 * </ul>
-	 * Note - this value is different to <tt>tokenDataLength</tt>
-	 */
-	public int getEncodedSize() {
-		return 2 + _byteEncoding.length;
-	}
-	/**
-	 * This method is often used when the formula length does not appear immediately before
-	 * the encoded token data.
-	 * 
-	 * @return the encoded length of the plain formula tokens.  This does <em>not</em> include
-	 * the leading ushort field, nor any trailing array constant data.
-	 */
-	public int getEncodedTokenSize() {
-		return _encodedTokenLen;
-	}
-	
-	/**
-	 * Creates a {@link Formula} object from a supplied {@link Ptg} array. 
-	 * Handles <code>null</code>s OK.
-	 * @param ptgs may be <code>null</code>
-	 * @return Never <code>null</code> (Possibly empty if the supplied <tt>ptgs</tt> is <code>null</code>)
-	 */
-	public static Formula create(Ptg[] ptgs) {
-		if (ptgs == null || ptgs.length < 1) {
-			return EMPTY;
-		}
-		int totalSize = Ptg.getEncodedSize(ptgs);
-		byte[] encodedData = new byte[totalSize];
-		Ptg.serializePtgs(ptgs, encodedData, 0);
-		int encodedTokenLen = Ptg.getEncodedSizeWithoutArrayData(ptgs);
-		return new Formula(encodedData, encodedTokenLen);
-	}
-	/**
-	 * Gets the {@link Ptg} array from the supplied {@link Formula}. 
-	 * Handles <code>null</code>s OK.
-	 * 
-	 * @param formula may be <code>null</code>
-	 * @return possibly <code>null</code> (if the supplied <tt>formula</tt> is <code>null</code>)
-	 */
-	public static Ptg[] getTokens(Formula formula) {
-		if (formula == null) {
-			return null;
-		}
-		return formula.getTokens();
-	}
-	
-	public Formula copy() {
-		// OK to return this because immutable
-		return this;
-	}
-	
-	/**
-	 * Gets the locator for the corresponding {@link SharedFormulaRecord}, {@link ArrayRecord} or
-	 * {@link TableRecord} if this formula belongs to such a grouping.  The {@link CellReference}
-	 * returned by this method will  match the top left corner of the range of that grouping. 
-	 * The return value is usually not the same as the location of the cell containing this formula.
-	 * 
-	 * @return the firstRow & firstColumn of an array formula or shared formula that this formula
-	 * belongs to.  <code>null</code> if this formula is not part of an array or shared formula.
-	 */
-	public CellReference getExpReference() {
-		byte[] data = _byteEncoding;
-		if (data.length != 5) {
-			// tExp and tTbl are always 5 bytes long, and the only ptg in the formula
-			return null;
-		}
-		switch (data[0]) {
-			case ExpPtg.sid:
-				break;
-			case TblPtg.sid:
-				break;
-			default:
-				return null;
-		}
-		int firstRow = LittleEndian.getUShort(data, 1);
-		int firstColumn = LittleEndian.getUShort(data, 3);
-		return new CellReference(firstRow, firstColumn);
-	}
-	public boolean isSame(Formula other) {
-		return Arrays.equals(_byteEncoding, other._byteEncoding);
-	}
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula;
+
+import java.util.Arrays;
+
+import org.apache.poi.hssf.record.ArrayRecord;
+import org.apache.poi.hssf.record.SharedFormulaRecord;
+import org.apache.poi.hssf.record.TableRecord;
+import org.apache.poi.hssf.record.formula.ExpPtg;
+import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.hssf.record.formula.TblPtg;
+import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianByteArrayInputStream;
+import org.apache.poi.util.LittleEndianInput;
+import org.apache.poi.util.LittleEndianOutput;
+
+/**
+ * Encapsulates an encoded formula token array.
+ *
+ * @author Josh Micich
+ */
+public class Formula {
+
+	private static final Formula EMPTY = new Formula(new byte[0], 0);
+
+	/** immutable */
+	private final byte[] _byteEncoding;
+	private final int _encodedTokenLen;
+
+	private Formula(byte[] byteEncoding, int encodedTokenLen) {
+		_byteEncoding = byteEncoding;
+		_encodedTokenLen = encodedTokenLen;
+		if (false) { // set to true to eagerly check Ptg decoding
+			LittleEndianByteArrayInputStream in = new LittleEndianByteArrayInputStream(byteEncoding);
+			Ptg.readTokens(encodedTokenLen, in);
+			int nUnusedBytes = _byteEncoding.length - in.getReadIndex();
+			if (nUnusedBytes > 0) {
+				// TODO - this seems to occur when IntersectionPtg is present
+				// This example file "IntersectionPtg.xls"
+				// used by test: TestIntersectionPtg.testReading()
+				// has 10 bytes unused at the end of the formula
+				// 10 extra bytes are just 0x01 and 0x00
+				System.out.println(nUnusedBytes + " unused bytes at end of formula");
+			}
+		}
+	}
+	/**
+	 * Convenience method for {@link #read(int, LittleEndianInput, int)}
+	 */
+	public static Formula read(int encodedTokenLen, LittleEndianInput in) {
+		return read(encodedTokenLen, in, encodedTokenLen);
+	}
+	/**
+	 * When there are no array constants present, <tt>encodedTokenLen</tt>==<tt>totalEncodedLen</tt>
+	 * @param encodedTokenLen number of bytes in the stream taken by the plain formula tokens
+	 * @param totalEncodedLen the total number of bytes in the formula (includes trailing encoding
+	 * for array constants, but does not include 2 bytes for initial <tt>ushort encodedTokenLen</tt> field.
+	 * @return A new formula object as read from the stream.  Possibly empty, never <code>null</code>.
+	 */
+	public static Formula read(int encodedTokenLen, LittleEndianInput in, int totalEncodedLen) {
+		byte[] byteEncoding = new byte[totalEncodedLen];
+		in.readFully(byteEncoding);
+		return new Formula(byteEncoding, encodedTokenLen);
+	}
+
+	public Ptg[] getTokens() {
+		LittleEndianInput in = new LittleEndianByteArrayInputStream(_byteEncoding);
+		return Ptg.readTokens(_encodedTokenLen, in);
+	}
+	/**
+	 * Writes  The formula encoding is includes:
+	 * <ul>
+	 * <li>ushort tokenDataLen</li>
+	 * <li>tokenData</li>
+	 * <li>arrayConstantData (if present)</li>
+	 * </ul>
+	 */
+	public void serialize(LittleEndianOutput out) {
+		out.writeShort(_encodedTokenLen);
+		out.write(_byteEncoding);
+	}
+
+	public void serializeTokens(LittleEndianOutput out) {
+		out.write(_byteEncoding, 0, _encodedTokenLen);
+	}
+	public void serializeArrayConstantData(LittleEndianOutput out) {
+		int len = _byteEncoding.length-_encodedTokenLen;
+		out.write(_byteEncoding, _encodedTokenLen, len);
+	}
+
+
+	/**
+	 * @return total formula encoding length.  The formula encoding includes:
+	 * <ul>
+	 * <li>ushort tokenDataLen</li>
+	 * <li>tokenData</li>
+	 * <li>arrayConstantData (optional)</li>
+	 * </ul>
+	 * Note - this value is different to <tt>tokenDataLength</tt>
+	 */
+	public int getEncodedSize() {
+		return 2 + _byteEncoding.length;
+	}
+	/**
+	 * This method is often used when the formula length does not appear immediately before
+	 * the encoded token data.
+	 *
+	 * @return the encoded length of the plain formula tokens.  This does <em>not</em> include
+	 * the leading ushort field, nor any trailing array constant data.
+	 */
+	public int getEncodedTokenSize() {
+		return _encodedTokenLen;
+	}
+
+	/**
+	 * Creates a {@link Formula} object from a supplied {@link Ptg} array.
+	 * Handles <code>null</code>s OK.
+	 * @param ptgs may be <code>null</code>
+	 * @return Never <code>null</code> (Possibly empty if the supplied <tt>ptgs</tt> is <code>null</code>)
+	 */
+	public static Formula create(Ptg[] ptgs) {
+		if (ptgs == null || ptgs.length < 1) {
+			return EMPTY;
+		}
+		int totalSize = Ptg.getEncodedSize(ptgs);
+		byte[] encodedData = new byte[totalSize];
+		Ptg.serializePtgs(ptgs, encodedData, 0);
+		int encodedTokenLen = Ptg.getEncodedSizeWithoutArrayData(ptgs);
+		return new Formula(encodedData, encodedTokenLen);
+	}
+	/**
+	 * Gets the {@link Ptg} array from the supplied {@link Formula}.
+	 * Handles <code>null</code>s OK.
+	 *
+	 * @param formula may be <code>null</code>
+	 * @return possibly <code>null</code> (if the supplied <tt>formula</tt> is <code>null</code>)
+	 */
+	public static Ptg[] getTokens(Formula formula) {
+		if (formula == null) {
+			return null;
+		}
+		return formula.getTokens();
+	}
+
+	public Formula copy() {
+		// OK to return this because immutable
+		return this;
+	}
+
+	/**
+	 * Gets the locator for the corresponding {@link SharedFormulaRecord}, {@link ArrayRecord} or
+	 * {@link TableRecord} if this formula belongs to such a grouping.  The {@link CellReference}
+	 * returned by this method will  match the top left corner of the range of that grouping.
+	 * The return value is usually not the same as the location of the cell containing this formula.
+	 *
+	 * @return the firstRow & firstColumn of an array formula or shared formula that this formula
+	 * belongs to.  <code>null</code> if this formula is not part of an array or shared formula.
+	 */
+	public CellReference getExpReference() {
+		byte[] data = _byteEncoding;
+		if (data.length != 5) {
+			// tExp and tTbl are always 5 bytes long, and the only ptg in the formula
+			return null;
+		}
+		switch (data[0]) {
+			case ExpPtg.sid:
+				break;
+			case TblPtg.sid:
+				break;
+			default:
+				return null;
+		}
+		int firstRow = LittleEndian.getUShort(data, 1);
+		int firstColumn = LittleEndian.getUShort(data, 3);
+		return new CellReference(firstRow, firstColumn);
+	}
+	public boolean isSame(Formula other) {
+		return Arrays.equals(_byteEncoding, other._byteEncoding);
+	}
+}

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java?rev=776377&r1=776376&r2=776377&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/FormulaParsingWorkbook.java Tue May 19 16:29:51 2009
@@ -1,55 +1,55 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-
-package org.apache.poi.ss.formula;
-
-import org.apache.poi.hssf.record.formula.NameXPtg;
-import org.apache.poi.ss.SpreadsheetVersion;
-
-/**
- * Abstracts a workbook for the purpose of formula parsing.<br/>
- * 
- * For POI internal use only
- * 
- * @author Josh Micich
- */
-public interface FormulaParsingWorkbook {
-	/**
-	 *  named range name matching is case insensitive
-	 */
-    EvaluationName getName(String name, int sheetIndex);
-
-	NameXPtg getNameXPtg(String name);
-
-	/**
-	 * gets the externSheet index for a sheet from this workbook
-	 */
-	int getExternalSheetIndex(String sheetName);
-	/**
-	 * gets the externSheet index for a sheet from an external workbook
-	 * @param workbookName e.g. "Budget.xls"
-	 * @param sheetName a name of a sheet in that workbook
-	 */
-	int getExternalSheetIndex(String workbookName, String sheetName);
-
-    /**
-     * Returns an enum holding spreadhseet properties specific to an Excel version (
-     * max column and row numbers, max arguments to a function, etc.)
-     */
-    SpreadsheetVersion getSpreadsheetVersion();
-
-}
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.formula;
+
+import org.apache.poi.hssf.record.formula.NameXPtg;
+import org.apache.poi.ss.SpreadsheetVersion;
+
+/**
+ * Abstracts a workbook for the purpose of formula parsing.<br/>
+ *
+ * For POI internal use only
+ *
+ * @author Josh Micich
+ */
+public interface FormulaParsingWorkbook {
+	/**
+	 *  named range name matching is case insensitive
+	 */
+	EvaluationName getName(String name, int sheetIndex);
+
+	NameXPtg getNameXPtg(String name);
+
+	/**
+	 * gets the externSheet index for a sheet from this workbook
+	 */
+	int getExternalSheetIndex(String sheetName);
+	/**
+	 * gets the externSheet index for a sheet from an external workbook
+	 * @param workbookName e.g. "Budget.xls"
+	 * @param sheetName a name of a sheet in that workbook
+	 */
+	int getExternalSheetIndex(String workbookName, String sheetName);
+
+	/**
+	 * Returns an enum holding spreadhseet properties specific to an Excel version (
+	 * max column and row numbers, max arguments to a function, etc.)
+	 */
+	SpreadsheetVersion getSpreadsheetVersion();
+
+}



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