]> source.dussan.org Git - poi.git/commitdiff
Patch from David Law in bug #43093 - handle Area3D formula references that refer...
authorNick Burch <nick@apache.org>
Wed, 15 Aug 2007 13:58:12 +0000 (13:58 +0000)
committerNick Burch <nick@apache.org>
Wed, 15 Aug 2007 13:58:12 +0000 (13:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@566157 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java [new file with mode: 0644]

index be1def70bb6448a6767ff0aa254cc0b4b8ce7b19..3e41f0824f53975160a65824cab657148cbd478f 100644 (file)
@@ -36,6 +36,7 @@
     </devs>
 
         <release version="3.0.2-FINAL" date="2007-??-??">
+            <action dev="POI-DEVELOPERS" type="fix">43093 - [PATCH] - Fix formula evaluator support for Area3D references to other sheets</action>
             <action dev="POI-DEVELOPERS" type="fix">Improvements to HSSFDateUtils.isADateFormat, and have HSSFDateUtil.isCellDateFormatted use this</action>
             <action dev="POI-DEVELOPERS" type="fix">42999 - [PATCH] - Fix for HSSFPatriarch positioning problems</action>
             <action dev="POI-DEVELOPERS" type="add">Support for write-protecting a HSSF workbook</action>
index 5fe08dbd44350c71c8ac210daf358e4c2eeb8250..2e07005efc8a128446572bbeda490f3b035df6e4 100644 (file)
@@ -33,6 +33,7 @@
 
     <changes>
         <release version="3.0.2-FINAL" date="2007-??-??">
+            <action dev="POI-DEVELOPERS" type="fix">43093 - [PATCH] - Fix formula evaluator support for Area3D references to other sheets</action>
             <action dev="POI-DEVELOPERS" type="fix">Improvements to HSSFDateUtils.isADateFormat, and have HSSFDateUtil.isCellDateFormatted use this</action>
             <action dev="POI-DEVELOPERS" type="fix">42999 - [PATCH] - Fix for HSSFPatriarch positioning problems</action>
             <action dev="POI-DEVELOPERS" type="add">Support for write-protecting a HSSF workbook</action>
index 26f931402fdb00dad80de154cbc4637a6d666a12..349c3fbb64aa1be92b37831c70c975f71e95eb54 100644 (file)
@@ -91,6 +91,7 @@ import org.apache.poi.hssf.record.formula.eval.SubtractEval;
 import org.apache.poi.hssf.record.formula.eval.UnaryMinusEval;
 import org.apache.poi.hssf.record.formula.eval.UnaryPlusEval;
 import org.apache.poi.hssf.record.formula.eval.ValueEval;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
 
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
@@ -369,10 +370,11 @@ public class HSSFFormulaEvaluator {
                 short col0 = a3dp.getFirstColumn();
                 short row1 = a3dp.getLastRow();
                 short col1 = a3dp.getLastColumn();
-                HSSFSheet xsheet = workbook.getSheetAt(a3dp.getExternSheetIndex());
+                Workbook wb = workbook.getWorkbook();
+                HSSFSheet xsheet = workbook.getSheetAt(wb.getSheetIndexFromExternSheetIndex(a3dp.getExternSheetIndex()));
                 ValueEval[] values = new ValueEval[(row1 - row0 + 1) * (col1 - col0 + 1)];
-                for (short x = row0; sheet != null && x < row1 + 1; x++) {
-                    HSSFRow row = sheet.getRow(x);
+                for (short x = row0; xsheet != null && x < row1 + 1; x++) {
+                    HSSFRow row = xsheet.getRow(x);
                     for (short y = col0; row != null && y < col1 + 1; y++) {
                         values[(x - row0) * (col1 - col0 + 1) + (y - col0)] = 
                             getEvalForCell(row.getCell(y), row, xsheet, workbook);
diff --git a/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java b/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java
new file mode 100644 (file)
index 0000000..8bfbac1
--- /dev/null
@@ -0,0 +1,42 @@
+package org.apache.poi.hssf.usermodel;
+
+import junit.framework.TestCase;
+
+public class TestBug43093 extends TestCase {
+
+       private static void addNewSheetWithCellsA1toD4(HSSFWorkbook book, int sheet) {
+               
+               HSSFSheet sht = book .createSheet("s" + sheet);
+               for     (short r=0; r < 4; r++) {
+                       
+                       HSSFRow   row = sht.createRow (r);
+                       for (short c=0; c < 4; c++) {
+                       
+                               HSSFCell cel = row.createCell(c);
+                               /**/     cel.setCellValue(sheet*100 + r*10 + c);
+                       }
+               }
+       }
+
+       public void testBug43093() throws Exception {
+                       HSSFWorkbook     xlw    = new HSSFWorkbook();
+
+                       addNewSheetWithCellsA1toD4(xlw, 1);
+                       addNewSheetWithCellsA1toD4(xlw, 2);
+                       addNewSheetWithCellsA1toD4(xlw, 3);
+                       addNewSheetWithCellsA1toD4(xlw, 4);
+
+                       HSSFSheet s2   = xlw.getSheet("s2");
+                       HSSFRow   s2r3 = s2.getRow(3);
+                       HSSFCell  s2E4 = s2r3.createCell((short)4);
+                       /**/      s2E4.setCellFormula("SUM(s3!B2:C3)");
+
+                       HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(s2, xlw);
+                       eva.setCurrentRow(s2r3);
+                       double d = eva.evaluate(s2E4).getNumberValue();
+
+                       // internalEvaluate(...) Area3DEval.: 311+312+321+322 expected
+                       assertEquals(d, (double)(311+312+321+322), 0.0000001);
+                       // System.out.println("Area3DEval ok.: 311+312+321+322=" + d);
+       }
+}