From: Nick Burch Date: Wed, 15 Aug 2007 13:58:12 +0000 (+0000) Subject: Patch from David Law in bug #43093 - handle Area3D formula references that refer... X-Git-Tag: REL_3_0_2_BETA1~68 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b1a8910fc362c1dfda52077c8f31631ece3d4427;p=poi.git Patch from David Law in bug #43093 - handle Area3D formula references that refer to a different sheet git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@566157 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index be1def70bb..3e41f0824f 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + 43093 - [PATCH] - Fix formula evaluator support for Area3D references to other sheets Improvements to HSSFDateUtils.isADateFormat, and have HSSFDateUtil.isCellDateFormatted use this 42999 - [PATCH] - Fix for HSSFPatriarch positioning problems Support for write-protecting a HSSF workbook diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 5fe08dbd44..2e07005efc 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 43093 - [PATCH] - Fix formula evaluator support for Area3D references to other sheets Improvements to HSSFDateUtils.isADateFormat, and have HSSFDateUtil.isCellDateFormatted use this 42999 - [PATCH] - Fix for HSSFPatriarch positioning problems Support for write-protecting a HSSF workbook diff --git a/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java b/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java index 26f931402f..349c3fbb64 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java +++ b/src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java @@ -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 < amolweb at ya hoo dot com > @@ -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 index 0000000000..8bfbac192e --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hssf/usermodel/TestBug43093.java @@ -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); + } +}