You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2007/08/15 15:58:14 UTC

svn commit: r566157 - in /poi/trunk/src: documentation/content/xdocs/ scratchpad/src/org/apache/poi/hssf/usermodel/ scratchpad/testcases/org/apache/poi/hssf/usermodel/

Author: nick
Date: Wed Aug 15 06:58:12 2007
New Revision: 566157

URL: http://svn.apache.org/viewvc?view=rev&rev=566157
Log:
Patch from David Law in bug #43093 - handle Area3D formula references that refer to a different sheet

Added:
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?view=diff&rev=566157&r1=566156&r2=566157
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Wed Aug 15 06:58:12 2007
@@ -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>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?view=diff&rev=566157&r1=566156&r2=566157
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Aug 15 06:58:12 2007
@@ -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>

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java?view=diff&rev=566157&r1=566156&r2=566157
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java Wed Aug 15 06:58:12 2007
@@ -91,6 +91,7 @@
 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 @@
                 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);

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java?view=auto&rev=566157
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java (added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java Wed Aug 15 06:58:12 2007
@@ -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);
+	}
+}

Propchange: poi/trunk/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java
------------------------------------------------------------------------------
    svn:eol-style = native



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