poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r675727 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/hssf/data/ testcases/org/apache/poi/hssf/usermodel/
Date Thu, 10 Jul 2008 20:54:42 GMT
Author: nick
Date: Thu Jul 10 13:54:42 2008
New Revision: 675727

URL: http://svn.apache.org/viewvc?rev=675727&view=rev
Log:
Fix cell.getRichStringCellValue() for formula cells with string results

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/data/43623.xls   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=675727&r1=675726&r2=675727&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Thu Jul 10 13:54:42 2008
@@ -37,6 +37,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">Fix cell.getRichStringCellValue()
for formula cells with string results</action>
            <action dev="POI-DEVELOPERS" type="fix">45365 - Handle more excel number
formatting rules in FormatTrackingHSSFListener / XLS2CSVmra</action>
            <action dev="POI-DEVELOPERS" type="fix">45373 - Improve the performance
of HSSFSheet.shiftRows</action>
            <action dev="POI-DEVELOPERS" type="fix">45367 - Fixed bug when last row
removed from sheet is row zero</action>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=675727&r1=675726&r2=675727&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Jul 10 13:54:42 2008
@@ -34,6 +34,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">Fix cell.getRichStringCellValue()
for formula cells with string results</action>
            <action dev="POI-DEVELOPERS" type="fix">45365 - Handle more excel number
formatting rules in FormatTrackingHSSFListener / XLS2CSVmra</action>
            <action dev="POI-DEVELOPERS" type="fix">45373 - Improve the performance
of HSSFSheet.shiftRows</action>
            <action dev="POI-DEVELOPERS" type="fix">45367 - Fixed bug when last row
removed from sheet is row zero</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=675727&r1=675726&r2=675727&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Thu Jul 10 13:54:42 2008
@@ -601,13 +601,28 @@
             // Set the 'pre-evaluated result' for the formula 
             // note - formulas do not preserve text formatting.
             FormulaRecordAggregate fr = (FormulaRecordAggregate) record;
-            // must make new sr because fr.getStringRecord() may be null
-            StringRecord sr = new StringRecord(); 
-            sr.setString(value.getString()); // looses format
-            fr.setStringRecord(sr);
+            
+            // Save the string into a String Record, creating
+            //  one if required
+            StringRecord sr = fr.getStringRecord();
+            if(sr == null) {
+            	// Wasn't a string before, need a new one
+            	sr = new StringRecord();
+                fr.setStringRecord(sr);
+            }
+            
+            // Save, loosing the formatting
+            sr.setString(value.getString());
+            // Update our local cache to the un-formatted version
+            stringValue = new HSSFRichTextString(sr.getString());
+            
+            // All done
             return;
         }
 
+        // If we get here, we're not dealing with a formula,
+        //  so handle things as a normal rich text cell
+        
         if (cellType != CELL_TYPE_STRING) {
             setCellType(CELL_TYPE_STRING, false, row, col, styleIndex);
         }

Added: poi/trunk/src/testcases/org/apache/poi/hssf/data/43623.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/43623.xls?rev=675727&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/data/43623.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=675727&r1=675726&r2=675727&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Thu Jul 10 13:54:42
2008
@@ -31,9 +31,7 @@
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.CellValueRecordInterface;
 import org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord;
-import org.apache.poi.hssf.record.FormulaRecord;
 import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
 import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
 import org.apache.poi.hssf.util.Region;
@@ -1151,10 +1149,12 @@
     	s.createRow(0);
     	HSSFCell c1 = s.getRow(0).createCell((short)0);
     	HSSFCell c2 = s.getRow(0).createCell((short)1);
+    	HSSFCell c3 = s.getRow(0).createCell((short)2);
 
     	// As number and string
     	c1.setCellFormula("70164");
     	c2.setCellFormula("\"70164\"");
+    	c3.setCellFormula("\"90210\"");
     	
     	// Check the formulas
     	assertEquals("70164.0", c1.getCellFormula());
@@ -1165,20 +1165,31 @@
     	assertEquals("", c1.getRichStringCellValue().getString());
     	assertEquals(0.0, c2.getNumericCellValue(), 0.00001);
     	assertEquals("", c2.getRichStringCellValue().getString());
+    	assertEquals(0.0, c3.getNumericCellValue(), 0.00001);
+    	assertEquals("", c3.getRichStringCellValue().getString());
     	
-    	// Now evaluate
+    	// Try changing the cached value on one of the string
+    	//  formula cells, so we can see it updates properly
+    	c3.setCellValue(new HSSFRichTextString("test"));
+    	assertEquals(0.0, c3.getNumericCellValue(), 0.00001);
+    	assertEquals("test", c3.getRichStringCellValue().getString());
+    	
+    	
+    	// Now evaluate, they should all be changed
     	HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(s, wb);
     	eval.setCurrentRow(s.getRow(0));
     	eval.evaluateFormulaCell(c1);
     	eval.evaluateFormulaCell(c2);
+    	eval.evaluateFormulaCell(c3);
     	
-    	// Check
+    	// Check that the cells now contain
+    	//  the correct values
     	assertEquals(70164.0, c1.getNumericCellValue(), 0.00001);
     	assertEquals("", c1.getRichStringCellValue().getString());
     	assertEquals(0.0, c2.getNumericCellValue(), 0.00001);
-    	
-    	// TODO - why isn't this working?
-//    	assertEquals("70164", c2.getRichStringCellValue().getString());
+    	assertEquals("70164", c2.getRichStringCellValue().getString());
+    	assertEquals(0.0, c3.getNumericCellValue(), 0.00001);
+    	assertEquals("90210", c3.getRichStringCellValue().getString());
   
     	
     	// Write and read
@@ -1186,12 +1197,15 @@
     	HSSFSheet ns = nwb.getSheetAt(0);
     	HSSFCell nc1 = ns.getRow(0).getCell((short)0);
     	HSSFCell nc2 = ns.getRow(0).getCell((short)1);
+    	HSSFCell nc3 = ns.getRow(0).getCell((short)2);
     	
     	// Re-check
     	assertEquals(70164.0, nc1.getNumericCellValue(), 0.00001);
     	assertEquals("", nc1.getRichStringCellValue().getString());
     	assertEquals(0.0, nc2.getNumericCellValue(), 0.00001);
     	assertEquals("70164", nc2.getRichStringCellValue().getString());
+    	assertEquals(0.0, nc3.getNumericCellValue(), 0.00001);
+    	assertEquals("90210", nc3.getRichStringCellValue().getString());
     	
     	// Now check record level stuff too
     	ns.getSheet().setLoc(0);
@@ -1204,15 +1218,27 @@
     			if(fn == 0) {
     				assertEquals(70164.0, fr.getFormulaRecord().getValue(), 0.0001);
     				assertNull(fr.getStringRecord());
-    			} else {
+    			} else if (fn == 1) {
     				assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
     				assertNotNull(fr.getStringRecord());
     				assertEquals("70164", fr.getStringRecord().getString());
+    			} else {
+    				assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
+    				assertNotNull(fr.getStringRecord());
+    				assertEquals("90210", fr.getStringRecord().getString());
     			}
     			
     			fn++;
     		}
     	}
-    	assertEquals(2, fn);
+    	assertEquals(3, fn);
+    }
+    
+    /**
+     * Problem with "Vector Rows"
+     * @throws Exception
+     */
+    public void test43623() throws Exception {
+    	
     }
 }



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


Mime
View raw message