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
This commit is contained in:
Nick Burch 2007-08-15 13:58:12 +00:00
parent 4f98781194
commit 6708ebde80
4 changed files with 49 additions and 3 deletions

View 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>

View 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>

View 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);

View File

@ -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);
}
}