01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hssf.usermodel;
19:
20: import junit.framework.TestCase;
21:
22: public class TestBug43093 extends TestCase {
23:
24: private static void addNewSheetWithCellsA1toD4(HSSFWorkbook book,
25: int sheet) {
26:
27: HSSFSheet sht = book.createSheet("s" + sheet);
28: for (short r = 0; r < 4; r++) {
29:
30: HSSFRow row = sht.createRow(r);
31: for (short c = 0; c < 4; c++) {
32:
33: HSSFCell cel = row.createCell(c);
34: /**/cel.setCellValue(sheet * 100 + r * 10 + c);
35: }
36: }
37: }
38:
39: public void testBug43093() throws Exception {
40: HSSFWorkbook xlw = new HSSFWorkbook();
41:
42: addNewSheetWithCellsA1toD4(xlw, 1);
43: addNewSheetWithCellsA1toD4(xlw, 2);
44: addNewSheetWithCellsA1toD4(xlw, 3);
45: addNewSheetWithCellsA1toD4(xlw, 4);
46:
47: HSSFSheet s2 = xlw.getSheet("s2");
48: HSSFRow s2r3 = s2.getRow(3);
49: HSSFCell s2E4 = s2r3.createCell((short) 4);
50: /**/s2E4.setCellFormula("SUM(s3!B2:C3)");
51:
52: HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(s2, xlw);
53: eva.setCurrentRow(s2r3);
54: double d = eva.evaluate(s2E4).getNumberValue();
55:
56: // internalEvaluate(...) Area3DEval.: 311+312+321+322 expected
57: assertEquals(d, (double) (311 + 312 + 321 + 322), 0.0000001);
58: // System.out.println("Area3DEval ok.: 311+312+321+322=" + d);
59: }
60: }
|