poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r642557 - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/aggregates/ src/java/org/apache/poi/hssf/record/cf/ src/java/...
Date Sat, 29 Mar 2008 17:00:53 GMT
Author: nick
Date: Sat Mar 29 10:00:47 2008
New Revision: 642557

URL: http://svn.apache.org/viewvc?rev=642557&view=rev
Log:
Merged revisions 638001-638784,638786-639486,639488-639601,639603-639836 via svnmerge from

https://svn.apache.org/repos/asf/poi/trunk

........
  r638803 | nick | 2008-03-19 11:57:38 +0000 (Wed, 19 Mar 2008) | 1 line
  
  Added test to show that bug #41546 is already fixed. Also rename a test file to be more
consistent
........
  r638804 | nick | 2008-03-19 12:01:32 +0000 (Wed, 19 Mar 2008) | 1 line
  
  Add test to show that bug #43251 is already fixed
........
  r638812 | nick | 2008-03-19 12:28:56 +0000 (Wed, 19 Mar 2008) | 1 line
  
  Patch from Dmitriy from bug #30311 - Support for conditional formatting records
........
  r638815 | nick | 2008-03-19 12:49:35 +0000 (Wed, 19 Mar 2008) | 1 line
  
  Fix bug #44627 - improve the thread safety of POILogFactory
........
  r639231 | nick | 2008-03-20 10:06:59 +0000 (Thu, 20 Mar 2008) | 1 line
  
  Test relating to bug #44636
........
  r639232 | nick | 2008-03-20 10:16:15 +0000 (Thu, 20 Mar 2008) | 1 line
  
  Simple patch from Josh from bug #44636 - fix for RefVPtg and edit-in-excel oddness
........
  r639242 | nick | 2008-03-20 11:02:39 +0000 (Thu, 20 Mar 2008) | 1 line
  
  Fix for readCompressedUnicode not moaning about length=0, from bug #44643
........
  r639254 | nick | 2008-03-20 11:43:14 +0000 (Thu, 20 Mar 2008) | 1 line
  
  Make junit happy
........
  r639836 | nick | 2008-03-21 21:04:47 +0000 (Fri, 21 Mar 2008) | 1 line
  
  Tweak how you get dataformat strings out of cell styles, to be more logical, and in keeping
with how we'll want to do things for xssf too
........

Added:
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/CFRuleRecord.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/record/CFRuleRecord.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/cf/
      - copied from r639254, poi/trunk/src/java/org/apache/poi/hssf/record/cf/
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/record/cf/BorderFormatting.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/cf/CellRange.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/record/cf/CellRange.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/record/cf/FontFormatting.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/cf/PatternFormatting.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/record/cf/PatternFormatting.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFBorderFormatting.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormatting.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFontFormatting.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java
      - copied unchanged from r639254, poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFPatternFormatting.java
    poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
      - copied unchanged from r639254, poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/41546.xls
      - copied unchanged from r639254, poi/trunk/src/testcases/org/apache/poi/hssf/data/41546.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/43251.xls
      - copied unchanged from r639254, poi/trunk/src/testcases/org/apache/poi/hssf/data/43251.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/44593.xls
      - copied unchanged from r639254, poi/trunk/src/testcases/org/apache/poi/hssf/data/44593.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/44636.xls
      - copied unchanged from r639254, poi/trunk/src/testcases/org/apache/poi/hssf/data/44636.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/44643.xls
      - copied unchanged from r639254, poi/trunk/src/testcases/org/apache/poi/hssf/data/44643.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java
      - copied unchanged from r639254, poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFHeaderRecord.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
      - copied unchanged from r639254, poi/trunk/src/testcases/org/apache/poi/hssf/record/TestCFRuleRecord.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
      - copied unchanged from r639254, poi/trunk/src/testcases/org/apache/poi/hssf/record/aggregates/TestCFRecordsAggregate.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/cf/
      - copied from r639254, poi/trunk/src/testcases/org/apache/poi/hssf/record/cf/
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java
      - copied unchanged from r639254, poi/trunk/src/testcases/org/apache/poi/hssf/record/cf/TestCellRange.java
Removed:
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/Bug44593.xls
Modified:
    poi/branches/ooxml/   (props changed)
    poi/branches/ooxml/src/documentation/content/xdocs/changes.xml
    poi/branches/ooxml/src/documentation/content/xdocs/status.xml
    poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Sheet.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RecordFactory.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RecordInputStream.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefVPtg.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
    poi/branches/ooxml/src/java/org/apache/poi/util/POILogFactory.java
    poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
    poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java
    poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java

Propchange: poi/branches/ooxml/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sat Mar 29 10:00:47 2008
@@ -1 +1 @@
-/poi/trunk:1-612483,612512,612520,613395-613401,614211,614274,614870,614878-614909,615190-618235,618328,618680-620582,627779-638000
+/poi/trunk:1-612483,612512,612520,613395-613401,614211,614274,614870,614878-614909,615190-618235,618328,618680-620582,627779-638784,638786-639486,639488-639601,639603-639836

Modified: poi/branches/ooxml/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/documentation/content/xdocs/changes.xml?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/documentation/content/xdocs/changes.xml (original)
+++ poi/branches/ooxml/src/documentation/content/xdocs/changes.xml Sat Mar 29 10:00:47 2008
@@ -36,6 +36,9 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">44636 - Fix formula parsing of RefVPtg,
which was causing #VALUE to be shown on subsequent edits</action>
+           <action dev="POI-DEVELOPERS" type="fix">44627 - Improve the thread safety
of POILogFactory</action>
+           <action dev="POI-DEVELOPERS" type="add">30311 - Initial support for Conditional
Formatting</action>
            <action dev="POI-DEVELOPERS" type="fix">44609 - Handle leading spaces in
formulas, such as '= 4'</action>
            <action dev="POI-DEVELOPERS" type="add">44608 - Support for PercentPtg in
the formula evaluator</action>
            <action dev="POI-DEVELOPERS" type="fix">44606 - Support calculated string
values for evaluated formulas</action>

Modified: poi/branches/ooxml/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/documentation/content/xdocs/status.xml?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/documentation/content/xdocs/status.xml (original)
+++ poi/branches/ooxml/src/documentation/content/xdocs/status.xml Sat Mar 29 10:00:47 2008
@@ -33,6 +33,9 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">44636 - Fix formula parsing of RefVPtg,
which was causing #VALUE to be shown on subsequent edits</action>
+           <action dev="POI-DEVELOPERS" type="fix">44627 - Improve the thread safety
of POILogFactory</action>
+           <action dev="POI-DEVELOPERS" type="add">30311 - Initial support for Conditional
Formatting</action>
            <action dev="POI-DEVELOPERS" type="fix">44609 - Handle leading spaces in
formulas, such as '= 4'</action>
            <action dev="POI-DEVELOPERS" type="add">44608 - Support for PercentPtg in
the formula evaluator</action>
            <action dev="POI-DEVELOPERS" type="fix">44606 - Support calculated string
values for evaluated formulas</action>

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Sheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Sheet.java?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Sheet.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Sheet.java Sat Mar 29 10:00:47 2008
@@ -24,6 +24,7 @@
 import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
 import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
 import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
+import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
 import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.hssf.util.PaneInformation;
 
@@ -96,6 +97,7 @@
     protected ObjectProtectRecord        objprotect        =     null;
     protected ScenarioProtectRecord      scenprotect       =     null;
     protected PasswordRecord             password          =     null;
+    protected List                       condFormatting    =     new ArrayList();;
 
     /** Add an UncalcedRecord if not true indicating formulas have not been calculated */

     protected boolean uncalced = false;
@@ -184,6 +186,17 @@
                 retval.merged = ( MergeCellsRecord ) rec;
                 retval.numMergedRegions += retval.merged.getNumAreas();
             }
+            else if ( rec.getSid() == CFHeaderRecord.sid )
+            {
+            	CFRecordsAggregate cfAgg = CFRecordsAggregate.createCFAggregate(recs, k);
+            	retval.condFormatting.add(cfAgg);
+            	rec = cfAgg;
+            }
+            else if ( rec.getSid() == CFRuleRecord.sid )
+            {
+            	// Skip it since it is processed by CFRecordsAggregate
+            	rec = null;
+            }
             else if (rec.getSid() == ColumnInfoRecord.sid)
             {
                 ColumnInfoRecord col = (ColumnInfoRecord)rec;
@@ -603,6 +616,66 @@
     public int getNumMergedRegions()
     {
         return numMergedRegions;
+    }
+    // Find correct position to add new CF record
+    private int findConditionalFormattingPosition()
+    {
+    	// This is default. 
+    	// If the algorithm does not find the right position,
+    	// this one will be used (this is a position before EOF record)
+    	int index = records.size()-2;
+    	
+    	for( int i=index; i>=0; i-- )
+    	{
+    		Record rec = (Record)records.get(i);
+    		short sid = rec.getSid();
+    		
+    		// CFRecordsAggregate records already exist, just add to the end
+    		if (rec instanceof CFRecordsAggregate)	{ return i+1; }
+    		
+    		if( sid == (short)0x00ef )				{ return i+1; }// PHONETICPR
+    		if( sid == (short)0x015f )				{ return i+1; }// LABELRANGES
+    		if( sid == MergeCellsRecord.sid )		{ return i+1; }
+    		if( sid == (short)0x0099 )				{ return i+1; }// STANDARDWIDTH
+    		if( sid == SelectionRecord.sid )		{ return i+1; }
+    		if( sid == PaneRecord.sid )				{ return i+1; }
+    		if( sid == SCLRecord.sid ) 				{ return i+1; }
+    		if( sid == WindowTwoRecord.sid )		{ return i+1; }
+    	}
+    	
+    	return index;
+    }
+
+    public int addConditionalFormatting(CFRecordsAggregate cfAggregate)
+    {
+    	int index = findConditionalFormattingPosition();
+    	records.add(index, cfAggregate);
+    	condFormatting.add(cfAggregate);
+    	return condFormatting.size()-1;
+    }
+
+    public void removeConditionalFormatting(int index)
+    {
+        if (index >= 0 && index <= condFormatting.size()-1 )
+        {
+        	CFRecordsAggregate cfAggregate = getCFRecordsAggregateAt(index);
+        	records.remove(cfAggregate);
+        	condFormatting.remove(index);
+        }
+    }
+    
+    public CFRecordsAggregate getCFRecordsAggregateAt(int index)
+    {
+        if (index >= 0 && index <= condFormatting.size()-1 )
+        {
+        	return (CFRecordsAggregate) condFormatting.get(index);
+        }
+        return null;
+    }
+    
+    public int getNumConditionalFormattings()
+    {
+    	return condFormatting.size();
     }
 
     /**

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RecordFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RecordFactory.java?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RecordFactory.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RecordFactory.java Sat Mar 29 10:00:47
2008
@@ -82,6 +82,8 @@
                 SupBookRecord.class,
                 CRNCountRecord.class,
                 CRNRecord.class,
+                CFHeaderRecord.class,
+                CFRuleRecord.class,
             };
     }
     private static Map           recordsMap  = recordsToMap(records);

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RecordInputStream.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RecordInputStream.java?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RecordInputStream.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RecordInputStream.java Sat Mar
29 10:00:47 2008
@@ -266,6 +266,9 @@
   }
     
   public String readCompressedUnicode(int length) {
+	if(length == 0) {
+		return "";
+	}
     if ((length < 0) || ((remaining() < length) && !isContinueNext())) {
             throw new IllegalArgumentException("Illegal length " + length);
     }
@@ -273,7 +276,7 @@
     StringBuffer buf = new StringBuffer(length);
     for (int i=0;i<length;i++) {
       if ((remaining() == 0) && (isContinueNext())) {
-        nextRecord();
+          nextRecord();
           int compressByte = readByte();
           if(compressByte != 0) throw new IllegalArgumentException("compressByte in continue
records must be 0 while reading compressed unicode");
       }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java Sat Mar
29 10:00:47 2008
@@ -180,19 +180,17 @@
       return ((getFirstRow() <= formulaRow) && (getLastRow() >= formulaRow)
&&
           (getFirstColumn() <= formulaColumn) && (getLastColumn() >= formulaColumn));
     }
-
-    /** Creates a non shared formula from the shared formula counter part*/
-    public void convertSharedFormulaRecord(FormulaRecord formula) {
-      //Sanity checks
-      final int formulaRow = formula.getRow();
-      final int formulaColumn = formula.getColumn();
-      if (isFormulaInShared(formula)) {
-        formula.setExpressionLength(getExpressionLength());
+    
+    /**
+     * Creates a non shared formula from the shared formula 
+     * counter part
+     */
+    protected static Stack convertSharedFormulas(Stack ptgs, int formulaRow, int formulaColumn)
{
         Stack newPtgStack = new Stack();
 
-        if (field_7_parsed_expr != null)
-          for (int k = 0; k < field_7_parsed_expr.size(); k++) {
-            Ptg ptg = (Ptg) field_7_parsed_expr.get(k);
+        if (ptgs != null)
+          for (int k = 0; k < ptgs.size(); k++) {
+            Ptg ptg = (Ptg) ptgs.get(k);
             if (ptg instanceof RefNPtg) {
               RefNPtg refNPtg = (RefNPtg)ptg;
               ptg = new ReferencePtg(fixupRelativeRow(formulaRow,refNPtg.getRow(),refNPtg.isRowRelative()),
@@ -243,7 +241,23 @@
                                 areaNAPtg.isLastColRelative());
             } 
             newPtgStack.add(ptg);
-          }
+        }
+        return newPtgStack;
+    }
+
+    /** 
+     * Creates a non shared formula from the shared formula 
+     * counter part
+     */
+    public void convertSharedFormulaRecord(FormulaRecord formula) {
+      //Sanity checks
+      final int formulaRow = formula.getRow();
+      final int formulaColumn = formula.getColumn();
+      if (isFormulaInShared(formula)) {
+        formula.setExpressionLength(getExpressionLength());
+        
+        Stack newPtgStack = 
+        	convertSharedFormulas(field_7_parsed_expr, formulaRow, formulaColumn);
         formula.setParsedExpression(newPtgStack);
         //Now its not shared!
         formula.setSharedFormula(false);
@@ -252,7 +266,7 @@
       }
     }
     
-    private int fixupRelativeColumn(int currentcolumn, int column, boolean relative) {
+    private static int fixupRelativeColumn(int currentcolumn, int column, boolean relative)
{
         if(relative) {
             // mask out upper bits to produce 'wrapping' at column 256 ("IV")
             return (column + currentcolumn) & 0x00FF;
@@ -260,7 +274,7 @@
         return column;
     }
 
-    private int fixupRelativeRow(int currentrow, int row, boolean relative) {
+    private static int fixupRelativeRow(int currentrow, int row, boolean relative) {
         if(relative) {
             // mask out upper bits to produce 'wrapping' at row 65536
             return (row+currentrow) & 0x00FFFF;

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefVPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefVPtg.java?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefVPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/RefVPtg.java Sat Mar 29
10:00:47 2008
@@ -32,6 +32,7 @@
 
   public RefVPtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
     super(row, column, isRowRelative, isColumnRelative);
+    setClass(CLASS_VALUE);
   }
 
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java Sat Mar 29
10:00:47 2008
@@ -277,11 +277,21 @@
     
     /**
      * Get the contents of the format string, by looking up
-     *  the DataFormat against the supplied workbook
+     *  the DataFormat against the bound workbook
      * @see org.apache.poi.hssf.usermodel.HSSFDataFormat
      */
     public String getDataFormatString() {
     	HSSFDataFormat format = new HSSFDataFormat(workbook);
+    	
+        return format.getFormat(getDataFormat());
+    }
+    /**
+     * Get the contents of the format string, by looking up
+     *  the DataFormat against the supplied workbook
+     * @see org.apache.poi.hssf.usermodel.HSSFDataFormat
+     */
+    public String getDataFormatString(org.apache.poi.ss.usermodel.Workbook workbook) {
+    	HSSFDataFormat format = new HSSFDataFormat( ((HSSFWorkbook)workbook).getWorkbook() );
     	
         return format.getFormat(getDataFormat());
     }

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=642557&r1=642556&r2=642557&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:00:47
2008
@@ -53,6 +53,7 @@
 import org.apache.poi.hssf.record.VCenterRecord;
 import org.apache.poi.hssf.record.WSBoolRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
+import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
 import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.hssf.record.formula.ReferencePtg;
 import org.apache.poi.hssf.util.HSSFCellRangeAddress;
@@ -1843,5 +1844,162 @@
         }
         return null;
     }
+
+
+     /**
+      * 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> 
+      * @param formula1 - formula for the valued, compared with the cell
+      * @param formula2 - second formula (only used with 
+      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and
+      * {@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)
+     {
+     	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

+      * 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. 
+      * 
+      * @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> 
+      * @param formula1 - formula for the valued, compared with the cell
+      * @param formula2 - second formula (only used with 
+      * {@link HSSFConditionalFormattingRule#COMPARISON_OPERATOR_BETWEEN}) and
+      * {@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)
+     {
+     	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
+      * 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 )
+     {
+      	HSSFConditionalFormatting cfClone = new HSSFConditionalFormatting(this,cf.cfAggregate.cloneCFAggregate());
+      	cfClone.sheet=this;
+     	return sheet.addConditionalFormatting(cfClone.cfAggregate);
+     }
+
+     /**
+      * 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( 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);
+     }
+     
+	/**
+	 * 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/java/org/apache/poi/util/POILogFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/util/POILogFactory.java?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/util/POILogFactory.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/util/POILogFactory.java Sat Mar 29 10:00:47
2008
@@ -33,14 +33,25 @@
 public class POILogFactory
 {
 
-    // map of POILogger instances, with classes as keys
-    private static Map          _loggers = new HashMap();;
-
+    /**
+     * Map of POILogger instances, with classes as keys
+     */
+    private static Map _loggers = new HashMap();;
 
     /**
-     * construct a POILogFactory.
+     * A common instance of NullLogger, as it does nothing
+     *  we only need the one
+     */
+    private static POILogger _nullLogger = new NullLogger();
+    /**
+     * The name of the class to use. Initialised the
+     *  first time we need it
      */
+    private static String _loggerClassName = null;
 
+    /**
+     * Construct a POILogFactory.
+     */
     private POILogFactory()
     {
     }
@@ -69,28 +80,48 @@
     public static POILogger getLogger(final String cat)
     {
         POILogger logger = null;
+        
+        // If we haven't found out what logger to use yet,
+        //  then do so now
+        // Don't look it up until we're first asked, so
+        //  that our users can set the system property
+        //  between class loading and first use
+        if(_loggerClassName == null) {
+        	try {
+        		_loggerClassName = System.getProperty("org.apache.poi.util.POILogger");
+        	} catch(Exception e) {}
+        	
+        	// Use the default logger if none specified,
+        	//  or none could be fetched
+        	if(_loggerClassName == null) {
+        		_loggerClassName = _nullLogger.getClass().getName();
+        	}
+        }
+        
+        // Short circuit for the null logger, which
+        //  ignores all categories
+        if(_loggerClassName.equals(_nullLogger.getClass().getName())) {
+        	return _nullLogger;
+        }
 
-        if (_loggers.containsKey(cat))
-        {
+        
+        // Fetch the right logger for them, creating
+        //  it if that's required 
+        if (_loggers.containsKey(cat)) {
             logger = ( POILogger ) _loggers.get(cat);
-        }
-        else
-        {
-            try{
-              String loggerClassName = System.getProperty("org.apache.poi.util.POILogger");
-              Class loggerClass = Class.forName(loggerClassName);
+        } else {
+            try {
+              Class loggerClass = Class.forName(_loggerClassName);
               logger = ( POILogger ) loggerClass.newInstance();
+              logger.initialize(cat);
+            } catch(Exception e) {
+              // Give up and use the null logger
+              logger = _nullLogger;
             }
-            catch(Exception e){
-            
-              logger = new NullLogger();
-            }
-            
-            logger.initialize(cat);
             
+            // Save for next time
             _loggers.put(cat, logger);
         }
         return logger;
     }
-        
-}   // end public class POILogFactory
+}   // end public class POILogFactory
\ No newline at end of file

Modified: poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
(original)
+++ poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
Sat Mar 29 10:00:47 2008
@@ -19,6 +19,7 @@
 
 import java.lang.reflect.Constructor;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Stack;
 
@@ -251,6 +252,35 @@
         }
         return cell;
     }
+    
+    /**
+     * Loops over all cells in all sheets of the supplied
+     *  workbook.
+     * For cells that contain formulas, their formulas are
+     *  evaluated, and the results are saved. These cells
+     *  remain as formula cells.
+     * For cells that do not contain formulas, no changes
+     *  are made.
+     * This is a helpful wrapper around looping over all 
+     *  cells, and calling evaluateFormulaCell on each one.
+     */
+	public static void evaluateAllFormulaCells(HSSFWorkbook wb) {
+		for(int i=0; i<wb.getNumberOfSheets(); i++) {
+			HSSFSheet sheet = wb.getSheetAt(i);
+			HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
+
+			for (Iterator rit = sheet.rowIterator(); rit.hasNext();) {
+				HSSFRow r = (HSSFRow)rit.next();
+				evaluator.setCurrentRow(r);
+
+				for (Iterator cit = r.cellIterator(); cit.hasNext();) {
+					HSSFCell c = (HSSFCell)cit.next();
+					if (c.getCellType() == HSSFCell.CELL_TYPE_FORMULA)
+						evaluator.evaluateFormulaCell(c);
+				}
+			}
+		}
+	}
         
     
     /**

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=642557&r1=642556&r2=642557&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:00:47 2008
@@ -1035,6 +1035,28 @@
     }
 
     /**
+     * Bug 41546: Constructing HSSFWorkbook is failed,
+     *  Unknown Ptg in Formula: 0x1a (26)
+     */
+    public void test41546() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "41546.xls"));
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+
+        assertTrue("No Exceptions while reading file", true);
+        assertEquals(1, wb.getNumberOfSheets());
+
+        //serialize and read again
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        wb.write(out);
+        out.close();
+
+        wb = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        assertTrue("No Exceptions while reading file", true);
+        assertEquals(1, wb.getNumberOfSheets());
+    }
+
+    /**
      * Bug 42564: Some files from Access were giving a RecordFormatException
      *  when reading the BOFRecord
      */
@@ -1115,6 +1137,20 @@
     }
     
     /**
+     * Something up with the FileSharingRecord
+     */
+    public void test43251() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "43251.xls"));
+        
+        // Used to blow up with an IllegalArgumentException
+        //  when creating a FileSharingRecord
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+        
+        assertEquals(1, wb.getNumberOfSheets());
+    }
+    
+    /**
      * Crystal reports generates files with short 
      *  StyleRecords, which is against the spec
      */
@@ -1157,7 +1193,7 @@
      *  probably due to dropdowns
      */
     public void test44593() throws Exception {
-        FileInputStream in = new FileInputStream(new File(cwd, "Bug44593.xls"));
+        FileInputStream in = new FileInputStream(new File(cwd, "44593.xls"));
         
         // Used to blow up with an IllegalArgumentException
         //  when creating a DVRecord
@@ -1167,6 +1203,20 @@
         in.close();
         
         assertEquals(2, wb.getNumberOfSheets());
+    }
+    
+    /**
+     * Used to give problems due to trying to read a zero
+     *  length string, but that's now properly handled
+     */
+    public void test44643() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "44643.xls"));
+        
+        // Used to blow up with an IllegalArgumentException
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+        
+        assertEquals(1, wb.getNumberOfSheets());
     }
 }
 

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java Sat
Mar 29 10:00:47 2008
@@ -36,23 +36,23 @@
 public class TestRawDataBlock
     extends TestCase
 {
+	static {
+        // We always want to use our own
+        //  logger
+        System.setProperty(
+        		"org.apache.poi.util.POILogger",
+        		"org.apache.poi.util.DummyPOILogger"
+        );
+	}
 
     /**
      * Constructor TestRawDataBlock
      *
      * @param name
      */
-
     public TestRawDataBlock(String name)
     {
         super(name);
-        
-        // We always want to use our own
-        //  logger
-        System.setProperty(
-        		"org.apache.poi.util.POILogger",
-        		"org.apache.poi.util.DummyPOILogger"
-        );
     }
 
     /**

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java?rev=642557&r1=642556&r2=642557&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java
Sat Mar 29 10:00:47 2008
@@ -36,23 +36,23 @@
 public class TestRawDataBlockList
     extends TestCase
 {
+	static {
+        // We always want to use our own
+        //  logger
+        System.setProperty(
+        		"org.apache.poi.util.POILogger",
+        		"org.apache.poi.util.DummyPOILogger"
+        );
+	}
 
     /**
      * Constructor TestRawDataBlockList
      *
      * @param name
      */
-
     public TestRawDataBlockList(String name)
     {
         super(name);
-        
-        // We always want to use our own
-        //  logger
-        System.setProperty(
-        		"org.apache.poi.util.POILogger",
-        		"org.apache.poi.util.DummyPOILogger"
-        );
     }
 
     /**
@@ -60,7 +60,6 @@
      *
      * @exception IOException
      */
-
     public void testNormalConstructor()
         throws IOException
     {



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


Mime
View raw message