]> source.dussan.org Git - poi.git/commitdiff
bug 35084, reported by Stefano Rocca. fixed in Sheet.java
authorAvik Sengupta <avik@apache.org>
Tue, 31 May 2005 19:03:19 +0000 (19:03 +0000)
committerAvik Sengupta <avik@apache.org>
Tue, 31 May 2005 19:03:19 +0000 (19:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353704 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/model/Sheet.java
src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java

index 363ece29062708d4ce0f7319024af7aa823bb5a7..fcfc5edff57aeffcab69a0e7cc65b36e90fb0db9 100644 (file)
@@ -340,9 +340,20 @@ public class Sheet implements Model
           ValueRecordsAggregate vrAgg = (ValueRecordsAggregate)rec;
           for (Iterator cellIter = vrAgg.getIterator();cellIter.hasNext();) {
             Record valRec = (Record)cellIter.next();
-            clonedRecords.add(valRec);
+            
+            if (valRec instanceof FormulaRecordAggregate) {
+                FormulaRecordAggregate fmAgg = (FormulaRecordAggregate)valRec;
+                Record fmAggRec = fmAgg.getFormulaRecord();
+                if (fmAggRec != null)
+                  clonedRecords.add(fmAggRec);
+                fmAggRec =   fmAgg.getStringRecord();
+                if (fmAggRec != null)
+                  clonedRecords.add(fmAggRec);
+              } else {
+                clonedRecords.add(valRec);
+              }
           }
-        } else if (rec instanceof FormulaRecordAggregate) {
+        } else if (rec instanceof FormulaRecordAggregate) {  //Is this required now??
           FormulaRecordAggregate fmAgg = (FormulaRecordAggregate)rec;
           Record fmAggRec = fmAgg.getFormulaRecord();
           if (fmAggRec != null)
index 508bf8572755fead2e7b5229e08c49b1d37599ec..08e41ae0ed7a668b1967bc28cc35d3b491a2d6ee 100644 (file)
@@ -234,5 +234,4 @@ public class FormulaRecordAggregate
         if(stringRecord==null) return null;
         return stringRecord.getString();
    }
-
 }
index 24c67dc9794c316439ed373f864c3528769dce4d..a603c27532380420525a8f1829b6ec6bc9f4ec8d 100644 (file)
@@ -437,6 +437,22 @@ public class TestHSSFSheet
         assertEquals("HSSFSheet.getLeftCol()", leftcol, sheet.getLeftCol());
     }
     
+    /** cell with formula becomes null on cloning a sheet*/
+        public void test35084() {
+       
+       HSSFWorkbook wb = new HSSFWorkbook();
+       HSSFSheet s =wb.createSheet("Sheet1");
+       HSSFRow r = s.createRow(0);
+       r.createCell((short)0).setCellValue(1);
+       r.createCell((short)1).setCellFormula("A1*2");
+       HSSFSheet s1 = wb.cloneSheet(0);
+       r=s1.getRow(0);
+       assertEquals("double" ,r.getCell((short)0).getNumericCellValue(),(double)1,0); //sanity check
+       assertNotNull(r.getCell((short)1)); 
+       assertEquals("formula", r.getCell((short)1).getCellFormula(), "A1*2");
+   }
+        
+        
        public static void main(java.lang.String[] args) {
                 junit.textui.TestRunner.run(TestHSSFSheet.class);
        }    
index 810109add1191f6a8d2cc7d6c3c2a3c04da94c39..36d85daaadfb35df4d4ec48fd9673847b3df8182 100644 (file)
@@ -59,21 +59,4 @@ public class TestUnfixedBugs extends TestCase {
        assertTrue("Read book fine!" , true);
    }
        
-        /* cell with formula becomes null on cloning a sheet*/
-        public void test35084() {
-       
-       HSSFWorkbook wb = new HSSFWorkbook();
-       HSSFSheet s =wb.createSheet("Sheet1");
-       HSSFRow r = s.createRow(0);
-       r.createCell((short)0).setCellValue(1);
-       r.createCell((short)1).setCellFormula("A1*2");
-       HSSFSheet s1 = wb.cloneSheet(0);
-       r=s1.getRow(0);
-       assertEquals("double" ,r.getCell((short)0).getNumericCellValue(),(double)1,0); //sanity check, pass
-       assertNotNull(r.getCell((short)1)); //Fails
-       assertEquals("formula", r.getCell((short)1).getCellFormula(), "A1*2"); //Fails
-       
-       
-       
-    }
 }