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

svn commit: r642560 [3/3] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/documentation/content/xdocs/hwpf/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/aggregates/ src/j...

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=642560&r1=642559&r2=642560&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 29 10:19:09 2008
@@ -15,11 +15,6 @@
    limitations under the License.
 ==================================================================== */
 
-/*
- * HSSFSheet.java
- *
- * Created on September 30, 2001, 3:40 PM
- */
 package org.apache.poi.hssf.usermodel;
 
 import java.awt.font.FontRenderContext;
@@ -374,7 +369,7 @@
     {
         return lastrow;
     }
-    
+
     /**
      * Creates a data validation object
      * @param obj_validation The Data validation object settings
@@ -610,25 +605,25 @@
     }
 
     /**
-     * Whether a record must be inserted or not at generation to indicate that 
+     * Whether a record must be inserted or not at generation to indicate that
      * formula must be recalculated when workbook is opened.
      * @param value true if an uncalced record must be inserted or not at generation
      */
     public void setForceFormulaRecalculation(boolean value)
     {
-    	sheet.setUncalced(value);
+        sheet.setUncalced(value);
     }
     /**
-     * Whether a record must be inserted or not at generation to indicate that 
+     * Whether a record must be inserted or not at generation to indicate that
      * formula must be recalculated when workbook is opened.
      * @return true if an uncalced record must be inserted or not at generation
      */
     public boolean getForceFormulaRecalculation()
     {
-    	return sheet.getUncalced();
+        return sheet.getUncalced();
     }
 
-    
+
     /**
      * determines whether the output is vertically centered on the page.
      * @param value true to vertically center, false otherwise.
@@ -728,13 +723,13 @@
         return rows.values().iterator();
     }
     /**
-     * Alias for {@link #rowIterator()} to allow 
+     * Alias for {@link #rowIterator()} to allow
      *  foreach loops
      */
     public Iterator iterator() {
         return rowIterator();
     }
-    
+
 
     /**
      * used internally in the API to get the low level Sheet record represented by this
@@ -1015,45 +1010,45 @@
         getSheet().setMargin( margin, size );
     }
 
-	/**
-	 * Answer whether protection is enabled or disabled
-	 * @return true => protection enabled; false => protection disabled
-	 */
-	public boolean getProtect() {
-		return getSheet().isProtected()[0];
-	}
-
-	/**
-	 * @return hashed password
-	 */
-	public short getPassword() {
-		return getSheet().getPassword().getPassword();
-	}
-
-	/**
-	 * Answer whether object protection is enabled or disabled
-	 * @return true => protection enabled; false => protection disabled
-	 */
-	public boolean getObjectProtect() {
-		return getSheet().isProtected()[1];
-	}
-
-	/**
-	 * Answer whether scenario protection is enabled or disabled
-	 * @return true => protection enabled; false => protection disabled
-	 */
-	public boolean getScenarioProtect() {
-		return getSheet().isProtected()[2];
-	}
-
-	/**
-	 * Sets the protection on enabled or disabled
-	 * @param protect true => protection enabled; false => protection disabled
+    /**
+     * Answer whether protection is enabled or disabled
+     * @return true => protection enabled; false => protection disabled
+     */
+    public boolean getProtect() {
+        return getSheet().isProtected()[0];
+    }
+
+    /**
+     * @return hashed password
+     */
+    public short getPassword() {
+        return getSheet().getPassword().getPassword();
+    }
+
+    /**
+     * Answer whether object protection is enabled or disabled
+     * @return true => protection enabled; false => protection disabled
+     */
+    public boolean getObjectProtect() {
+        return getSheet().isProtected()[1];
+    }
+
+    /**
+     * Answer whether scenario protection is enabled or disabled
+     * @return true => protection enabled; false => protection disabled
+     */
+    public boolean getScenarioProtect() {
+        return getSheet().isProtected()[2];
+    }
+
+    /**
+     * Sets the protection on enabled or disabled
+     * @param protect true => protection enabled; false => protection disabled
          * @deprecated use protectSheet(String, boolean, boolean)
-	 */
-	public void setProtect(boolean protect) {
-		getSheet().getProtect().setProtect(protect);
-	}
+     */
+    public void setProtect(boolean protect) {
+        getSheet().getProtect().setProtect(protect);
+    }
 
         /**
          * Sets the protection enabled as well as the password
@@ -1083,29 +1078,29 @@
         sclRecord.setDenominator((short)denominator);
         getSheet().setSCLRecord(sclRecord);
     }
-    
+
     /**
-     * The top row in the visible view when the sheet is 
-     * first viewed after opening it in a viewer 
+     * The top row in the visible view when the sheet is
+     * first viewed after opening it in a viewer
      * @return short indicating the rownum (0 based) of the top row
      */
-    public short getTopRow() 
+    public short getTopRow()
     {
-    	return sheet.getTopRow();
+        return sheet.getTopRow();
     }
-    
+
     /**
-     * The left col in the visible view when the sheet is 
-     * first viewed after opening it in a viewer 
+     * The left col in the visible view when the sheet is
+     * first viewed after opening it in a viewer
      * @return short indicating the rownum (0 based) of the top row
      */
-    public short getLeftCol() 
+    public short getLeftCol()
     {
-    	return sheet.getLeftCol();
+        return sheet.getLeftCol();
     }
-    
+
     /**
-     * Sets desktop window pane display area, when the 
+     * Sets desktop window pane display area, when the
      * file is first opened in a viewer.
      * @param toprow the top row to show in desktop window pane
      * @param leftcol the left column to show in desktop window pane
@@ -1115,49 +1110,49 @@
         this.sheet.setLeftCol((short)leftcol);
         }
 
-	/**
-	 * Shifts the merged regions left or right depending on mode
-	 * <p>
-	 * TODO: MODE , this is only row specific
-	 * @param startRow
-	 * @param endRow
-	 * @param n
-	 * @param isRow
-	 */
-	protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) {
-		List shiftedRegions = new ArrayList();
-		//move merged regions completely if they fall within the new region boundaries when they are shifted
-		for (int i = 0; i < this.getNumMergedRegions(); i++) {
-			 Region merged = this.getMergedRegionAt(i);
-
-			 boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow);
-			 boolean inEnd =  (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow);
-
-			 //dont check if it's not within the shifted area
-			 if (! (inStart && inEnd)) continue;
-
-			 //only shift if the region outside the shifted rows is not merged too
-			 if (!merged.contains(startRow-1, (short)0) && !merged.contains(endRow+1, (short)0)){
-				 merged.setRowFrom(merged.getRowFrom()+n);
-				 merged.setRowTo(merged.getRowTo()+n);
-				 //have to remove/add it back
-				 shiftedRegions.add(merged);
-				 this.removeMergedRegion(i);
-				 i = i -1; // we have to back up now since we removed one
-
-			 }
-
-		}
-
-		//readd so it doesn't get shifted again
-		Iterator iterator = shiftedRegions.iterator();
-		while (iterator.hasNext()) {
-			Region region = (Region)iterator.next();
+    /**
+     * Shifts the merged regions left or right depending on mode
+     * <p>
+     * TODO: MODE , this is only row specific
+     * @param startRow
+     * @param endRow
+     * @param n
+     * @param isRow
+     */
+    protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) {
+        List shiftedRegions = new ArrayList();
+        //move merged regions completely if they fall within the new region boundaries when they are shifted
+        for (int i = 0; i < this.getNumMergedRegions(); i++) {
+             Region merged = this.getMergedRegionAt(i);
+
+             boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow);
+             boolean inEnd =  (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow);
+
+             //dont check if it's not within the shifted area
+             if (! (inStart && inEnd)) continue;
+
+             //only shift if the region outside the shifted rows is not merged too
+             if (!merged.contains(startRow-1, (short)0) && !merged.contains(endRow+1, (short)0)){
+                 merged.setRowFrom(merged.getRowFrom()+n);
+                 merged.setRowTo(merged.getRowTo()+n);
+                 //have to remove/add it back
+                 shiftedRegions.add(merged);
+                 this.removeMergedRegion(i);
+                 i = i -1; // we have to back up now since we removed one
+
+             }
+
+        }
+
+        //readd so it doesn't get shifted again
+        Iterator iterator = shiftedRegions.iterator();
+        while (iterator.hasNext()) {
+            Region region = (Region)iterator.next();
 
-			this.addMergedRegion(region);
-		}
+            this.addMergedRegion(region);
+        }
 
-	}
+    }
 
     /**
      * Shifts rows between startRow and endRow n number of rows.
@@ -1174,7 +1169,7 @@
      * @param n the number of rows to shift
      */
     public void shiftRows( int startRow, int endRow, int n ) {
-		shiftRows(startRow, endRow, n, false, false);
+        shiftRows(startRow, endRow, n, false, false);
     }
 
     /**
@@ -1211,7 +1206,7 @@
 
         shiftMerged(startRow, endRow, n, true);
         sheet.shiftRowBreaks(startRow, endRow, n);
-			
+
         for ( int rowNum = s; rowNum >= startRow && rowNum <= endRow && rowNum >= 0 && rowNum < 65536; rowNum += inc )
         {
             HSSFRow row = getRow( rowNum );
@@ -1224,23 +1219,23 @@
 
 
 
-	    // Removes the cells before over writting them.
+        // Removes the cells before over writting them.
             for ( short col = row2Replace.getFirstCellNum(); col <= row2Replace.getLastCellNum(); col++ )
             {
                 cell = row2Replace.getCell( col );
                 if ( cell != null )
                     row2Replace.removeCell( cell );
             }
-	    if (row == null) continue; // Nothing to do for this row
-	    else {
-		if (copyRowHeight) {
-		    row2Replace.setHeight(row.getHeight());
-		}
-
-		if (resetOriginalRowHeight) {
-		    row.setHeight((short)0xff);
-		}
-	    }
+        if (row == null) continue; // Nothing to do for this row
+        else {
+        if (copyRowHeight) {
+            row2Replace.setHeight(row.getHeight());
+        }
+
+        if (resetOriginalRowHeight) {
+            row.setHeight((short)0xff);
+        }
+        }
             for ( short col = row.getFirstCellNum(); col <= row.getLastCellNum(); col++ )
             {
                 cell = row.getCell( col );
@@ -1262,55 +1257,55 @@
         }
         if ( endRow == lastrow || endRow + n > lastrow ) lastrow = Math.min( endRow + n, 65535 );
         if ( startRow == firstrow || startRow + n < firstrow ) firstrow = Math.max( startRow + n, 0 );
-        
+
         // Update any formulas on this sheet that point to
         //  rows which have been moved
         updateFormulasAfterShift(startRow, endRow, n);
     }
-    
+
     /**
      * Called by shiftRows to update formulas on this sheet
      *  to point to the new location of moved rows
      */
     private void updateFormulasAfterShift(int startRow, int endRow, int n) {
-    	// Need to look at every cell on the sheet
-    	// Not just those that were moved
+        // Need to look at every cell on the sheet
+        // Not just those that were moved
         Iterator ri = rowIterator();
         while(ri.hasNext()) {
-        	HSSFRow r = (HSSFRow)ri.next();
-        	Iterator ci = r.cellIterator();
-        	while(ci.hasNext()) {
-        		HSSFCell c = (HSSFCell)ci.next();
-        		if(c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
-        			// Since it's a formula cell, process the
-        			//  formula string, and look to see if
-        			//  it contains any references
-        			FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook.getWorkbook());
-        			fp.parse();
-        			
-        			// Look for references, and update if needed
-        			Ptg[] ptgs = fp.getRPNPtg();
-        			boolean changed = false;
-        			for(int i=0; i<ptgs.length; i++) {
-        				if(ptgs[i] instanceof ReferencePtg) {
-        					ReferencePtg rptg = (ReferencePtg)ptgs[i];
-        					if(startRow <= rptg.getRowAsInt() &&
-        							rptg.getRowAsInt() <= endRow) {
-        						// References a row that moved
-        						rptg.setRow(rptg.getRowAsInt() + n);
-        						changed = true;
-        					}
-        				}
-        			}
-        			// If any references were changed, then
-        			//  re-create the formula string
-        			if(changed) {
-        				c.setCellFormula(
-        						fp.toFormulaString(ptgs)
-        				);
-        			}
-        		}
-        	}
+            HSSFRow r = (HSSFRow)ri.next();
+            Iterator ci = r.cellIterator();
+            while(ci.hasNext()) {
+                HSSFCell c = (HSSFCell)ci.next();
+                if(c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
+                    // Since it's a formula cell, process the
+                    //  formula string, and look to see if
+                    //  it contains any references
+                    FormulaParser fp = new FormulaParser(c.getCellFormula(), workbook.getWorkbook());
+                    fp.parse();
+
+                    // Look for references, and update if needed
+                    Ptg[] ptgs = fp.getRPNPtg();
+                    boolean changed = false;
+                    for(int i=0; i<ptgs.length; i++) {
+                        if(ptgs[i] instanceof ReferencePtg) {
+                            ReferencePtg rptg = (ReferencePtg)ptgs[i];
+                            if(startRow <= rptg.getRowAsInt() &&
+                                    rptg.getRowAsInt() <= endRow) {
+                                // References a row that moved
+                                rptg.setRow(rptg.getRowAsInt() + n);
+                                changed = true;
+                            }
+                        }
+                    }
+                    // If any references were changed, then
+                    //  re-create the formula string
+                    if(changed) {
+                        c.setCellFormula(
+                                fp.toFormulaString(ptgs)
+                        );
+                    }
+                }
+            }
         }
     }
 
@@ -1363,7 +1358,7 @@
     {
         getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane );
     }
-    
+
     /**
      * Returns the information regarding the currently configured pane (split or freeze).
      * @return null if no pane configured, or the pane information.
@@ -1385,7 +1380,7 @@
      * @return whether gridlines are displayed
      */
     public boolean isDisplayGridlines() {
-	return sheet.isDisplayGridlines();
+    return sheet.isDisplayGridlines();
     }
 
     /**
@@ -1401,7 +1396,7 @@
      * @return whether formulas are displayed
      */
     public boolean isDisplayFormulas() {
-    	return sheet.isDisplayFormulas();
+        return sheet.isDisplayFormulas();
     }
 
     /**
@@ -1417,16 +1412,16 @@
      * @return whether RowColHeadings are displayed
      */
     public boolean isDisplayRowColHeadings() {
-    	return sheet.isDisplayRowColHeadings();
+        return sheet.isDisplayRowColHeadings();
     }
-    
+
     /**
      * Sets a page break at the indicated row
      * @param row FIXME: Document this!
      */
     public void setRowBreak(int row) {
-    	validateRow(row);
-    	sheet.setRowBreak(row, (short)0, (short)255);
+        validateRow(row);
+        sheet.setRowBreak(row, (short)0, (short)255);
     }
 
     /**
@@ -1435,35 +1430,35 @@
      * @return FIXME: Document this!
      */
     public boolean isRowBroken(int row) {
-    	return sheet.isRowBroken(row);
+        return sheet.isRowBroken(row);
     }
-    
+
     /**
      * Removes the page break at the indicated row
      * @param row
      */
     public void removeRowBreak(int row) {
-    	sheet.removeRowBreak(row);
+        sheet.removeRowBreak(row);
     }
-    
+
     /**
      * Retrieves all the horizontal page breaks
      * @return all the horizontal page breaks, or null if there are no row page breaks
      */
     public int[] getRowBreaks(){
-    	//we can probably cache this information, but this should be a sparsely used function
-    	int count = sheet.getNumRowBreaks();
-    	if (count > 0) {
-    	  int[] returnValue = new int[count];
-    	  Iterator iterator = sheet.getRowBreaks();
-    	  int i = 0;
-    	  while (iterator.hasNext()) {
-    		PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-    		returnValue[i++] = (int)breakItem.main;
-    	  }
-    	  return returnValue;
-    	}
-    	return null;
+        //we can probably cache this information, but this should be a sparsely used function
+        int count = sheet.getNumRowBreaks();
+        if (count > 0) {
+          int[] returnValue = new int[count];
+          Iterator iterator = sheet.getRowBreaks();
+          int i = 0;
+          while (iterator.hasNext()) {
+            PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
+            returnValue[i++] = (int)breakItem.main;
+          }
+          return returnValue;
+        }
+        return null;
     }
 
     /**
@@ -1471,29 +1466,29 @@
      * @return all the vertical page breaks, or null if there are no column page breaks
      */
     public short[] getColumnBreaks(){
-    	//we can probably cache this information, but this should be a sparsely used function 
-    	int count = sheet.getNumColumnBreaks();
-    	if (count > 0) {
-    	  short[] returnValue = new short[count];
-    	  Iterator iterator = sheet.getColumnBreaks();
-    	  int i = 0;
-    	  while (iterator.hasNext()) {
-    		PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-    		returnValue[i++] = breakItem.main;
-    	  }
-    	  return returnValue;
-    	}
-    	return null;
+        //we can probably cache this information, but this should be a sparsely used function
+        int count = sheet.getNumColumnBreaks();
+        if (count > 0) {
+          short[] returnValue = new short[count];
+          Iterator iterator = sheet.getColumnBreaks();
+          int i = 0;
+          while (iterator.hasNext()) {
+            PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
+            returnValue[i++] = breakItem.main;
+          }
+          return returnValue;
+        }
+        return null;
     }
-    
-    
+
+
     /**
      * Sets a page break at the indicated column
      * @param column
      */
     public void setColumnBreak(short column) {
-    	validateColumn(column);
-    	sheet.setColumnBreak(column, (short)0, (short)65535);
+        validateColumn(column);
+        sheet.setColumnBreak(column, (short)0, (short)65535);
     }
 
     /**
@@ -1502,33 +1497,33 @@
      * @return FIXME: Document this!
      */
     public boolean isColumnBroken(short column) {
-    	return sheet.isColumnBroken(column);
+        return sheet.isColumnBroken(column);
     }
-    
+
     /**
      * Removes a page break at the indicated column
      * @param column
      */
     public void removeColumnBreak(short column) {
-    	sheet.removeColumnBreak(column);
+        sheet.removeColumnBreak(column);
     }
-    
+
     /**
      * Runs a bounds check for row numbers
      * @param row
      */
     protected void validateRow(int row) {
-    	if (row > 65535) throw new IllegalArgumentException("Maximum row number is 65535");
-    	if (row < 0) throw new IllegalArgumentException("Minumum row number is 0");
+        if (row > 65535) throw new IllegalArgumentException("Maximum row number is 65535");
+        if (row < 0) throw new IllegalArgumentException("Minumum row number is 0");
     }
-    
+
     /**
      * Runs a bounds check for column numbers
      * @param column
      */
     protected void validateColumn(short column) {
-    	if (column > 255) throw new IllegalArgumentException("Maximum column number is 255");
-    	if (column < 0)	throw new IllegalArgumentException("Minimum column number is 0");
+        if (column > 255) throw new IllegalArgumentException("Maximum column number is 255");
+        if (column < 0)    throw new IllegalArgumentException("Minimum column number is 0");
     }
 
     /**
@@ -1573,7 +1568,7 @@
         agg.setPatriarch(patriarch);
         return patriarch;
     }
-    
+
     /**
      * Returns the top-level drawing patriach, if there is
      *  one.
@@ -1587,32 +1582,32 @@
      *  start from scratch!
      */
     public HSSFPatriarch getDrawingPatriarch() {
-    	book.findDrawingGroup();
-    	
-    	// If there's now no drawing manager, then there's
-    	//  no drawing escher records on the workbook
-    	if(book.getDrawingManager() == null) {
-    		return null;
-    	}
-    	
-    	int found = sheet.aggregateDrawingRecords(
-    			book.getDrawingManager(), false
-    	);
-    	if(found == -1) {
-    		// Workbook has drawing stuff, but this sheet doesn't
-    		return null;
-    	}
-    	
-    	// Grab our aggregate record, and wire it up
+        book.findDrawingGroup();
+
+        // If there's now no drawing manager, then there's
+        //  no drawing escher records on the workbook
+        if(book.getDrawingManager() == null) {
+            return null;
+        }
+
+        int found = sheet.aggregateDrawingRecords(
+                book.getDrawingManager(), false
+        );
+        if(found == -1) {
+            // Workbook has drawing stuff, but this sheet doesn't
+            return null;
+        }
+
+        // Grab our aggregate record, and wire it up
         EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
         HSSFPatriarch patriarch = new HSSFPatriarch(this, agg);
         agg.setPatriarch(patriarch);
-        
+
         // Have it process the records into high level objects
         //  as best it can do (this step may eat anything
         //  that isn't supported, you were warned...)
         agg.convertRecordsToUserModel();
-        
+
         // Return what we could cope with
         return patriarch;
     }
@@ -1666,7 +1661,7 @@
      * @param style the style to set
      */
     public void setDefaultColumnStyle(short column, CellStyle style) {
-	sheet.setColumn(column, new Short(((HSSFCellStyle) style).getIndex()), null, null, null, null);
+       sheet.setColumn(column, new Short(((HSSFCellStyle) style).getIndex()), null, null, null, null);
     }
 
     /**
@@ -1687,13 +1682,13 @@
          * '0' looks to be a good choice.
          */
         char defaultChar = '0';
-       
+
         /**
          * This is the multiple that the font height is scaled by when determining the
          * boundary of rotated text.
          */
         double fontHeightMultiple = 2.0;
-       
+
         FontRenderContext frc = new FontRenderContext(null, true, true);
 
         HSSFWorkbook wb = new HSSFWorkbook(book);
@@ -1814,7 +1809,7 @@
     /**
      * Copy text attributes from the supplied HSSFFont to Java2D AttributedString
      */
-    private void copyAttributes(HSSFFont font, AttributedString str, int startIdx, int endIdx){
+    private void copyAttributes(HSSFFont font, AttributedString str, int startIdx, int endIdx) {
         str.addAttribute(TextAttribute.FAMILY, font.getFontName(), startIdx, endIdx);
         str.addAttribute(TextAttribute.SIZE, new Float(font.getFontHeightInPoints()));
         if (font.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) str.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIdx, endIdx);
@@ -1847,86 +1842,86 @@
 
 
      /**
-      * A factory method allowing to create a conditional formatting rule 
-      * with a cell comparison operator and 
+      * A factory method allowing to create a conditional formatting rule
+      * with a cell comparison operator and
       * formatting rules such as font format, border format and pattern format
-      * 
+      *
       * @param comparisonOperation - one of the following values: <p>
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
-      * </p> 
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
+      * </p>
       * @param formula1 - formula for the valued, compared with the cell
-      * @param formula2 - second formula (only used with 
+      * @param formula2 - second formula (only used with
       * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and
-      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)   
+      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)
       * @param fontFmt - font formatting rules
       * @param bordFmt - border formatting rules
       * @param patternFmt - pattern formatting rules
       * @return
-      * 
+      *
       */
      public HSSFConditionalFormattingRule createConditionalFormattingRule(
-     		byte comparisonOperation, 
-     		String formula1, 
-     		String formula2,
-     		HSSFFontFormatting fontFmt,
- 			HSSFBorderFormatting bordFmt, 
- 			HSSFPatternFormatting patternFmt)
+             byte comparisonOperation,
+             String formula1,
+             String formula2,
+             HSSFFontFormatting fontFmt,
+             HSSFBorderFormatting bordFmt,
+             HSSFPatternFormatting patternFmt)
      {
-     	HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook);
- 		cf.setFontFormatting(fontFmt);
- 		cf.setBorderFormatting(bordFmt);
- 		cf.setPatternFormatting(patternFmt);
- 		cf.setCellComparisonCondition(comparisonOperation, formula1, formula2);
-     	return cf;
+         HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook);
+         cf.setFontFormatting(fontFmt);
+         cf.setBorderFormatting(bordFmt);
+         cf.setPatternFormatting(patternFmt);
+         cf.setCellComparisonCondition(comparisonOperation, formula1, formula2);
+         return cf;
      }
 
      /**
-      * A factory method allowing to create a conditional formatting rule with a formula 
+      * A factory method allowing to create a conditional formatting rule with a formula
       * and formatting rules such as font format, border format and pattern format. <br>
-      * 
-      * The formatting rules are applied by Excel when the value of the formula not equal to 0. 
-      * 
+      *
+      * The formatting rules are applied by Excel when the value of the formula not equal to 0.
+      *
       * @param comparisonOperation - one of the following values: <p>
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li> 
-      * 		<li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
-      * </p> 
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_EQUAL}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_EQUAL}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GT}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LT}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_GE}</li>
+      *         <li>{@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_LE}</li>
+      * </p>
       * @param formula1 - formula for the valued, compared with the cell
-      * @param formula2 - second formula (only used with 
+      * @param formula2 - second formula (only used with
       * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and
-      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)   
+      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_NOT_BETWEEN} operations)
       * @param fontFmt - font formatting rules
       * @param bordFmt - border formatting rules
       * @param patternFmt - pattern formatting rules
       * @return
-      * 
+      *
       */
      public HSSFConditionalFormattingRule createConditionalFormattingRule(
-     		String formula, 
-     		HSSFFontFormatting fontFmt,
- 			HSSFBorderFormatting bordFmt, 
- 			HSSFPatternFormatting patternFmt)
+             String formula,
+             HSSFFontFormatting fontFmt,
+             HSSFBorderFormatting bordFmt,
+             HSSFPatternFormatting patternFmt)
      {
-     	HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook);
- 		cf.setFontFormatting(fontFmt);
- 		cf.setBorderFormatting(bordFmt);
- 		cf.setPatternFormatting(patternFmt);
- 		cf.setFormulaCondition(formula);
-     	return cf;
+         HSSFConditionalFormattingRule cf = new HSSFConditionalFormattingRule(workbook);
+         cf.setFontFormatting(fontFmt);
+         cf.setBorderFormatting(bordFmt);
+         cf.setPatternFormatting(patternFmt);
+         cf.setFormulaCondition(formula);
+         return cf;
      }
-     
+
      /**
       * Adds a copy of HSSFConditionalFormatting object to the sheet
       * <p>This method could be used to copy HSSFConditionalFormatting object
@@ -1934,72 +1929,71 @@
       * <pre>
       * HSSFConditionalFormatting cf = sheet.getConditionalFormattingAt(index);
       * newSheet.addConditionalFormatting(cf);
-      * </pre>  
-      * 
+      * </pre>
+      *
       * @param cf HSSFConditionalFormatting object
       * @return index of the new Conditional Formatting object
       */
      public int addConditionalFormatting( HSSFConditionalFormatting cf )
      {
-      	HSSFConditionalFormatting cfClone = new HSSFConditionalFormatting(this,cf.cfAggregate.cloneCFAggregate());
-      	cfClone.sheet=this;
-     	return sheet.addConditionalFormatting(cfClone.cfAggregate);
+         CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
+
+         return sheet.addConditionalFormatting(cfraClone);
      }
 
      /**
       * Allows to add a new Conditional Formatting set to the sheet.
-      *  
-      * @param regions - list of rectangular regions to apply conditional formatting rules 
+      *
+      * @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( Region [] regions, HSSFConditionalFormattingRule [] cfRules )
      {
-     	HSSFConditionalFormatting cf = new HSSFConditionalFormatting(this);
-     	cf.setFormattingRegions(regions);
-     	if( cfRules != null )
-     	{
-     		for( int i=0; i!= cfRules.length; i++ )
-     		{
-     	    	cf.addConditionalFormat(cfRules[i]);
-     		}
-     	}
-     	return sheet.addConditionalFormatting(cf.cfAggregate);
+         HSSFConditionalFormatting cf = new HSSFConditionalFormatting(this);
+         cf.setFormattingRegions(regions);
+         if( cfRules != null )
+         {
+             for( int i=0; i!= cfRules.length; i++ )
+             {
+                 cf.addRule(cfRules[i]);
+             }
+         }
+         return sheet.addConditionalFormatting(cf.getCFRecordsAggregate());
      }
-     
-	/**
-	 * 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 = sheet.getCFRecordsAggregateAt(index);
-		if( cf != null )
-		{
-			return new HSSFConditionalFormatting(this,cf);
-		}
-		return null;
-	}
-
-	/**
-	 * @return number of Conditional Formatting objects of the sheet
-	 */
-	public int getNumConditionalFormattings()
-	{
-		return sheet.getNumConditionalFormattings();
-	}
-
-	/**
-	 * removes a Conditional Formatting object by index
-	 * @param index of a Conditional Formatting object to remove
-	 */
-	public void removeConditionalFormatting(int index)
-	{
-		sheet.removeConditionalFormatting(index);
-	}
 
+    /**
+     * 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 = sheet.getCFRecordsAggregateAt(index);
+        if( cf != null )
+        {
+            return new HSSFConditionalFormatting(this,cf);
+        }
+        return null;
+    }
+
+    /**
+     * @return number of Conditional Formatting objects of the sheet
+     */
+    public int getNumConditionalFormattings()
+    {
+        return sheet.getNumConditionalFormattings();
+    }
+
+    /**
+     * removes a Conditional Formatting object by index
+     * @param index of a Conditional Formatting object to remove
+     */
+    public void removeConditionalFormatting(int index)
+    {
+        sheet.removeConditionalFormatting(index);
+    }
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Pmt.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Pmt.java?rev=642560&r1=642559&r2=642560&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Pmt.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Pmt.java Sat Mar 29 10:19:09 2008
@@ -14,61 +14,78 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-/*
- * Created on May 15, 2005
- *
- */
 package org.apache.poi.hssf.record.formula.functions;
 
 import org.apache.poi.hssf.record.formula.eval.BoolEval;
 import org.apache.poi.hssf.record.formula.eval.ErrorEval;
 import org.apache.poi.hssf.record.formula.eval.Eval;
+import org.apache.poi.hssf.record.formula.eval.EvaluationException;
 import org.apache.poi.hssf.record.formula.eval.NumberEval;
 import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
 import org.apache.poi.hssf.record.formula.eval.ValueEval;
 
-public class Pmt extends FinanceFunction {
+/**
+ * Implementation for the PMT() Excel function.<p/>
+ * 
+ * <b>Syntax:</b><br/>
+ * <b>PMT</b>(<b>rate</b>, <b>nper</b>, <b>pv</b>, fv, type)<p/>
+ * 
+ * Returns the constant repayment amount required for a loan assuming a constant interest rate.<p/>
+ * 
+ * <b>rate</b> the loan interest rate.<br/>
+ * <b>nper</b> the number of loan repayments.<br/>
+ * <b>pv</b> the present value of the future payments (or principle).<br/>
+ * <b>fv</b> the future value (default zero) surplus cash at the end of the loan lifetime.<br/>
+ * <b>type</b> whether payments are due at the beginning(1) or end(0 - default) of each payment period.<br/>
+ * 
+ */
+public final class Pmt extends FinanceFunction {
+
+	public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
+		
+		if(args.length < 3 || args.length > 5) {
+			return ErrorEval.VALUE_INVALID;
+		}
+		
+ 		try {
+ 			// evaluate first three (always present) args
+			double rate = evalArg(args[0], srcRow, srcCol);
+			double nper = evalArg(args[1], srcRow, srcCol);
+			double pv  = evalArg(args[2], srcRow, srcCol); 
+			double fv = 0;
+			boolean arePaymentsAtPeriodBeginning = false;
+			
+			switch (args.length) {
+				case 5:
+					ValueEval ve = singleOperandNumericAsBoolean(args[4], srcRow, srcCol);
+					if (ve instanceof ErrorEval) { 
+						return ve;
+					}
+					arePaymentsAtPeriodBeginning = ((BoolEval) ve).getBooleanValue();
+				case 4:
+					fv = evalArg(args[3], srcRow, srcCol);
+			}
+			double d = FinanceLib.pmt(rate, nper, pv, fv, arePaymentsAtPeriodBeginning);
+			if (Double.isNaN(d)) {
+				return (ValueEval) ErrorEval.VALUE_INVALID;
+			}
+			if (Double.isInfinite(d)) {
+				return (ValueEval) ErrorEval.NUM_ERROR;
+			}
+			return new NumberEval(d);
+		} catch (EvaluationException e) {
+			return e.getErrorEval();
+		}
+	}
 
-    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
-        double rate = 0, fv = 0, nper = 0, pv = 0, d = 0;
-        boolean type = false;
-        ValueEval retval = null;
-        ValueEval ve = null;
-        
-        switch (operands.length) {
-        default:
-            retval = ErrorEval.VALUE_INVALID;
-            break;
-        case 5:
-            ve = singleOperandNumericAsBoolean(operands[4], srcRow, srcCol);
-            if (ve instanceof ErrorEval) { retval = ErrorEval.VALUE_INVALID; break; }
-            type = ((BoolEval) ve).getBooleanValue();
-        case 4:
-            ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
-            if (ve instanceof NumericValueEval) rate = ((NumericValueEval) ve).getNumberValue();
-            else { retval = ErrorEval.VALUE_INVALID; break; }
-            
-            ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
-            if (ve instanceof NumericValueEval) nper  = ((NumericValueEval) ve).getNumberValue();
-            else { retval = ErrorEval.VALUE_INVALID; break; }
-            
-            ve = singleOperandEvaluate(operands[2], srcRow, srcCol);
-            if (ve instanceof NumericValueEval) pv   = ((NumericValueEval) ve).getNumberValue();
-            else { retval = ErrorEval.VALUE_INVALID; break; }
-            
-            ve = singleOperandEvaluate(operands[3], srcRow, srcCol);
-            if (ve instanceof NumericValueEval) fv = ((NumericValueEval) ve).getNumberValue();
-            else { retval = ErrorEval.VALUE_INVALID; break; }
-        }
-        
-        if (retval == null) {
-            d = FinanceLib.pmt(rate, nper, pv, fv, type);
-            retval = (Double.isNaN(d))
-                    ? (ValueEval) ErrorEval.VALUE_INVALID
-                    : (Double.isInfinite(d)) 
-                        ? (ValueEval) ErrorEval.NUM_ERROR 
-                        : new NumberEval(d);
-        }
-        return retval;
-    }
+	private double evalArg(Eval arg, int srcRow, short srcCol) throws EvaluationException {
+		ValueEval ve = singleOperandEvaluate(arg, srcRow, srcCol);
+		if(ve instanceof ErrorEval) {
+			throw new EvaluationException((ErrorEval) ve);
+		}
+		if (ve instanceof NumericValueEval) {
+			return ((NumericValueEval) ve).getNumberValue();
+		}
+		throw new EvaluationException(ErrorEval.VALUE_INVALID); 
+	}
 }

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java?rev=642560&r1=642559&r2=642560&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java Sat Mar 29 10:19:09 2008
@@ -190,7 +190,7 @@
     }
     
     // read in the pictures stream
-    _pictures = new PicturesTable(_dataStream);
+    _pictures = new PicturesTable(this, _dataStream);
 
     // get the start of text in the main stream
     int fcMin = _fib.getFcMin();

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java?rev=642560&r1=642559&r2=642560&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java (original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hwpf/model/PicturesTable.java Sat Mar 29 10:19:09 2008
@@ -19,8 +19,10 @@
 package org.apache.poi.hwpf.model;
 
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.usermodel.CharacterRun;
 import org.apache.poi.hwpf.usermodel.Picture;
+import org.apache.poi.hwpf.usermodel.Range;
 
 import java.util.List;
 import java.util.ArrayList;
@@ -53,6 +55,7 @@
   static final int BLOCK_TYPE_OFFSET = 0xE;
   static final int MM_MODE_TYPE_OFFSET = 0x6;
 
+  private HWPFDocument _document;
   private byte[] _dataStream;
 
   /** @link dependency
@@ -61,10 +64,12 @@
 
   /**
    *
+   * @param document 
    * @param _dataStream
    */
-  public PicturesTable(byte[] _dataStream)
+  public PicturesTable(HWPFDocument _document, byte[] _dataStream)
   {
+	this._document = _document;
     this._dataStream = _dataStream;
   }
 
@@ -119,24 +124,25 @@
   }
 
   /**
+   * Not all documents have all the images concatenated in the data stream
+   * although MS claims so. The best approach is to scan all character runs.
+   *  
    * @return a list of Picture objects found in current document
    */
   public List getAllPictures() {
     ArrayList pictures = new ArrayList();
-    
-    int pos = 0;
-    boolean atEnd = false;
-    
-    while(pos<_dataStream.length && !atEnd) {
-      if (isBlockContainsImage(pos)) {
-        pictures.add(new Picture(pos, _dataStream, false));
-      }
-      
-      int skipOn = LittleEndian.getInt(_dataStream, pos);
-      if(skipOn <= 0) { atEnd = true; }
-      pos += skipOn;
-    }
-    
+	
+    Range range = _document.getRange();
+    for (int i = 0; i < range.numCharacterRuns(); i++) {
+    	CharacterRun run = range.getCharacterRun(i);
+    	String text = run.text();
+    	int j = text.charAt(0);
+    	Picture picture = extractPicture(run, false);
+    	if (picture != null) {
+    		pictures.add(picture);
+    	}
+	}
+
     return pictures;
   }
 

Modified: poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java?rev=642560&r1=642559&r2=642560&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java (original)
+++ poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java Sat Mar 29 10:19:09 2008
@@ -14,7 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record.formula.functions;
 
@@ -41,6 +40,7 @@
 		result.addTestSuite(TestMid.class);
 		result.addTestSuite(TestMathX.class);
 		result.addTestSuite(TestMatch.class);
+		result.addTestSuite(TestPmt.class);
 		result.addTestSuite(TestOffset.class);
 		result.addTestSuite(TestRowCol.class);
 		result.addTestSuite(TestSumproduct.class);
@@ -50,5 +50,4 @@
 		result.addTestSuite(TestXYNumericFunction.class);
 		return result;
 	}
-
 }

Modified: poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java?rev=642560&r1=642559&r2=642560&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java (original)
+++ poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestPictures.java Sat Mar 29 10:19:09 2008
@@ -17,18 +17,15 @@
 package org.apache.poi.hwpf.usermodel;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.FileInputStream;
-import java.util.Iterator;
 import java.util.List;
 
+import junit.framework.TestCase;
+
 import org.apache.poi.hwpf.HWPFDocument;
-import org.apache.poi.hwpf.model.TextPiece;
-import org.apache.poi.hwpf.usermodel.Paragraph;
-import org.apache.poi.hwpf.usermodel.Range;
 import org.apache.poi.util.LittleEndian;
 
-import junit.framework.TestCase;
-
 /**
  * Test the picture handling
  *
@@ -118,6 +115,12 @@
      * emf image, with a crazy offset
      */
     public void testEmfComplexImage() throws Exception {
+    	/*
+    	
+    	Commenting out this test case temporarily. The file emf_2003_image does not contain any
+    	pictures. Instead it has an office drawing object. Need to rewrite this test after
+    	revisiting the implementation of office drawing objects.
+    	
     	HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/emf_2003_image.doc"));
     	List pics = doc.getPicturesTable().getAllPictures();
     	
@@ -137,9 +140,17 @@
     	assertEquals(4, pic.getSize());
     	assertEquals(0x80000000l, LittleEndian.getUInt(pic.getContent()));
     	assertEquals(0x80000000l, LittleEndian.getUInt(pic.getRawContent()));
+    	*/
     }
-    
-    
+
+    public void testPicturesWithTable() throws Exception {
+    	HWPFDocument doc = new HWPFDocument(new FileInputStream(
+    			new File(dirname, "Bug44603.doc")));
+
+    	List pics = doc.getPicturesTable().getAllPictures();
+    	assertEquals(pics.size(), 2);
+    }
+
     private byte[] loadImage(String filename) throws Exception {
     	ByteArrayOutputStream b = new ByteArrayOutputStream();
     	FileInputStream fis = new FileInputStream(dirname + "/" + filename);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java?rev=642560&r1=642559&r2=642560&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java Sat Mar 29 10:19:09 2008
@@ -293,7 +293,7 @@
         assertEquals("FOO", tname.toFormulaString(w));
         
         AbstractFunctionPtg tfunc = (AbstractFunctionPtg) ptg[1];
-        assertEquals("externalflag", tfunc.getName());
+        assertTrue(tfunc.isExternalFunction());
     }
 
     public void testEmbeddedSlash() {
@@ -887,5 +887,18 @@
             // expected during successful test
             assertTrue(e.getMessage().startsWith("Too few arguments suppled to operation token"));
         }
+    }
+    public void testFuncPtgSelection() {
+        Workbook book = Workbook.createWorkbook();
+        Ptg[] ptgs;
+        ptgs = FormulaParser.parse("countif(A1:A2, 1)", book);
+        assertEquals(3, ptgs.length);
+        if(FuncVarPtg.class == ptgs[2].getClass()) {
+            throw new AssertionFailedError("Identified bug 44675");
+        }
+        assertEquals(FuncPtg.class, ptgs[2].getClass());
+        ptgs = FormulaParser.parse("sin(1)", book);
+        assertEquals(2, ptgs.length);
+        assertEquals(FuncPtg.class, ptgs[1].getClass());
     }
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java?rev=642560&r1=642559&r2=642560&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java Sat Mar 29 10:19:09 2008
@@ -14,7 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
@@ -28,10 +27,10 @@
  * 
  * @author Josh Micich
  */
-public class AllRecordTests {
+public final class AllRecordTests {
 	
 	public static Test suite() {
-		TestSuite result = new TestSuite("Tests for org.apache.poi.hssf.record");
+		TestSuite result = new TestSuite(AllRecordTests.class.getName());
 
 		result.addTest(AllFormulaTests.suite());
 		
@@ -56,6 +55,7 @@
 		result.addTestSuite(TestEmbeddedObjectRefSubRecord.class);
 		result.addTestSuite(TestEndSubRecord.class);
 		result.addTestSuite(TestEscherAggregate.class);
+		result.addTestSuite(TestExternalNameRecord.class);
 		result.addTestSuite(TestFontBasisRecord.class);
 		result.addTestSuite(TestFontIndexRecord.class);
 		result.addTestSuite(TestFormulaRecord.class);

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java?rev=642560&r1=642559&r2=642560&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/AllFormulaTests.java Sat Mar 29 10:19:09 2008
@@ -17,6 +17,8 @@
 
 package org.apache.poi.hssf.record.formula;
 
+import org.apache.poi.hssf.record.formula.function.AllFormulaFunctionTests;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -28,12 +30,12 @@
 public class AllFormulaTests {
 	
 	public static Test suite() {
-		TestSuite result = new TestSuite("Tests for org.apache.poi.hssf.record.formula");
+		TestSuite result = new TestSuite(AllFormulaTests.class.getName());
 		result.addTestSuite(TestArea3DPtg.class);
 		result.addTestSuite(TestAreaErrPtg.class);
-        result.addTestSuite(TestAreaPtg.class);
-        result.addTestSuite(TestErrPtg.class);
-        result.addTestSuite(TestExternalFunctionFormulas.class);
+		result.addTestSuite(TestAreaPtg.class);
+		result.addTestSuite(TestErrPtg.class);
+		result.addTestSuite(TestExternalFunctionFormulas.class);
 		result.addTestSuite(TestFuncPtg.class);
 		result.addTestSuite(TestIntersectionPtg.class);
 		result.addTestSuite(TestPercentPtg.class);
@@ -42,6 +44,7 @@
 		result.addTestSuite(TestReferencePtg.class);
 		result.addTestSuite(TestSheetNameFormatter.class);
 		result.addTestSuite(TestUnionPtg.class);
+		result.addTest(AllFormulaFunctionTests.suite());
 		return result;
 	}
 }

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=642560&r1=642559&r2=642560&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Sat Mar 29 10:19:09 2008
@@ -1218,6 +1218,30 @@
         
         assertEquals(1, wb.getNumberOfSheets());
     }
+    
+    /**
+     * User reported the wrong number of rows from the
+     *  iterator, but we can't replicate that
+     */
+    public void test44693() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "44693.xls"));
+        
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        HSSFSheet s = wb.getSheetAt(0);
+
+        // Rows are 1 to 713
+        assertEquals(0, s.getFirstRowNum());
+        assertEquals(712, s.getLastRowNum());
+        assertEquals(713, s.getPhysicalNumberOfRows());
+        
+        // Now check the iterator
+        int rowsSeen = 0;
+        for(Iterator i = s.rowIterator(); i.hasNext(); ) {
+        	HSSFRow r = (HSSFRow)i.next();
+        	rowsSeen++;
+        }
+        assertEquals(713, rowsSeen);
+    }
 }
 
 



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