From 99fbaec5a38c6ebe5c533c457a85afbde1b9b345 Mon Sep 17 00:00:00 2001 From: Avik Sengupta Date: Tue, 31 May 2005 19:03:19 +0000 Subject: [PATCH] bug 35084, reported by Stefano Rocca. fixed in Sheet.java 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 | 15 +++++++++++++-- .../aggregates/FormulaRecordAggregate.java | 1 - .../poi/hssf/usermodel/TestHSSFSheet.java | 16 ++++++++++++++++ .../poi/hssf/usermodel/TestUnfixedBugs.java | 17 ----------------- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 363ece290..fcfc5edff 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -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) diff --git a/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java index 508bf8572..08e41ae0e 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java @@ -234,5 +234,4 @@ public class FormulaRecordAggregate if(stringRecord==null) return null; return stringRecord.getString(); } - } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java index 24c67dc97..a603c2753 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java @@ -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); } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java index 810109add..36d85daaa 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java @@ -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 - - - - } }