Inspired by bug #44958 - Record level support for Data Tables. (No formula parser...
[poi.git] / src / testcases / org / apache / poi / hssf / usermodel / TestBug43093.java
blobce072e9e014e9ebcb00d2c1367739fdcc78dfa07
1 /* ====================================================================
2 Licensed to the Apache Software Foundation (ASF) under one or more
3 contributor license agreements. See the NOTICE file distributed with
4 this work for additional information regarding copyright ownership.
5 The ASF licenses this file to You under the Apache License, Version 2.0
6 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================== */
18 package org.apache.poi.hssf.usermodel;
20 import junit.framework.TestCase;
22 public class TestBug43093 extends TestCase {
24 private static void addNewSheetWithCellsA1toD4(HSSFWorkbook book, int sheet) {
26 HSSFSheet sht = book .createSheet("s" + sheet);
27 for (short r=0; r < 4; r++) {
29 HSSFRow row = sht.createRow (r);
30 for (short c=0; c < 4; c++) {
32 HSSFCell cel = row.createCell(c);
33 /**/ cel.setCellValue(sheet*100 + r*10 + c);
38 public void testBug43093() throws Exception {
39 HSSFWorkbook xlw = new HSSFWorkbook();
41 addNewSheetWithCellsA1toD4(xlw, 1);
42 addNewSheetWithCellsA1toD4(xlw, 2);
43 addNewSheetWithCellsA1toD4(xlw, 3);
44 addNewSheetWithCellsA1toD4(xlw, 4);
46 HSSFSheet s2 = xlw.getSheet("s2");
47 HSSFRow s2r3 = s2.getRow(3);
48 HSSFCell s2E4 = s2r3.createCell((short)4);
49 /**/ s2E4.setCellFormula("SUM(s3!B2:C3)");
51 HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(s2, xlw);
52 eva.setCurrentRow(s2r3);
53 double d = eva.evaluate(s2E4).getNumberValue();
55 // internalEvaluate(...) Area3DEval.: 311+312+321+322 expected
56 assertEquals(d, (double)(311+312+321+322), 0.0000001);
57 // System.out.println("Area3DEval ok.: 311+312+321+322=" + d);