Package org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator

Examples of org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue


    // were 4 and 1, this would represent a circular reference.  Prior to v3.2 POI would
    // 'fully' evaluate ref arguments before invoking operators, which raised the possibility of
    // cycles / StackOverflowErrors.
   

    CellValue cellValue = evaluateWithCycles(wb, testCell);
   
    assertTrue(cellValue.getCellType() == HSSFCell.CELL_TYPE_NUMERIC);
    assertEquals(2, cellValue.getNumberValue(), 0);
  }
View Full Code Here


   
    HSSFRow row = sheet.createRow(0);
    HSSFCell testCell = row.createCell(0);
    testCell.setCellFormula("A1");

    CellValue cellValue = evaluateWithCycles(wb, testCell);
   
    confirmCycleErrorCode(cellValue);
  }
View Full Code Here

    row.createCell(1).setCellFormula("C1");
    row.createCell(2).setCellFormula("D1");
    HSSFCell testCell = row.createCell(3);
    testCell.setCellFormula("A1");

    CellValue cellValue = evaluateWithCycles(wb, testCell);
   
    confirmCycleErrorCode(cellValue);
  }
View Full Code Here

    HSSFCell cell = row.createCell(0);
    cell.setCellFormula("B1%");
    row.createCell(1).setCellValue(50.0);
   
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv;
    try {
      cv = fe.evaluate(cell);
    } catch (RuntimeException e) {
      if(e.getCause() instanceof NullPointerException) {
        throw new AssertionFailedError("Identified bug 44608");
      }
      // else some other unexpected error
      throw e;
    }
    assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(0.5, cv.getNumberValue(), 0.0);
  }
View Full Code Here

    cell.setCellFormula("myFunc()");
    String actualFormula=cell.getCellFormula();
    assertEquals("myFunc()", actualFormula);
   
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue evalResult = fe.evaluate(cell);
   
    // Check the return value from ExternalFunction.evaluate()
    // TODO - make this test assert something more interesting as soon as ExternalFunction works a bit better
    assertEquals(HSSFCell.CELL_TYPE_ERROR, evalResult.getCellType());
    assertEquals(ErrorEval.FUNCTION_NOT_IMPLEMENTED.getErrorCode(), evalResult.getErrorValue());
  }
View Full Code Here

      HSSFRow row = sheet.getRow(rowIx);
      if(row == null) {
        continue;
      }
      HSSFCell cell = row.getCell(COL_IX_ACTUAL);
      CellValue cv = fe.evaluate(cell);
      double actualValue = cv.getNumberValue();
      double expectedValue = row.getCell(COL_IX_EXPECTED).getNumericCellValue();
      if (actualValue != expectedValue) {
        System.err.println("Problem with test case on row " + (rowIx+1) + " "
            + "Expected = (" + expectedValue + ") Actual=(" + actualValue + ") ");
        failureCount++;
View Full Code Here

        
        cell.setCellFormula("isblank(Sheet2!A1:A1)");
       
        HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
        CellValue result = fe.evaluate(cell);
        assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
        assertEquals(true, result.getBooleanValue());
       
        cell.setCellFormula("isblank(D7:D7)");
       
        result = fe.evaluate(cell);
        assertEquals(HSSFCell.CELL_TYPE_BOOLEAN, result.getCellType());
        assertEquals(true, result.getBooleanValue());
   }
View Full Code Here

  private static void confirmCellEval(HSSFSheet sheet, int rowIx, int colIx,
      HSSFFormulaEvaluator fe, String expectedFormula, double expectedResult) {
    HSSFCell cell = sheet.getRow(rowIx).getCell(colIx);
    assertEquals(expectedFormula, cell.getCellFormula());
    CellValue cv = fe.evaluate(cell);
    assertEquals(expectedResult, cv.getNumberValue(), 0.0);
  }
View Full Code Here

          System.out.println("\t" + c.substring(c.lastIndexOf('.')+1) );
        }
        System.out.println("-> " + cell.getCellFormula());
      }
     
      CellValue evalResult = eval.evaluate(cell);
      assertNotNull(evalResult);
    }
  }
View Full Code Here

  public void testEvaluateSimple() {
    HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testNames.xls");
    HSSFSheet sheet = wb.getSheetAt(0);
    HSSFCell cell = sheet.getRow(8).getCell(0);
    HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
    CellValue cv = fe.evaluate(cell);
    assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
    assertEquals(3.72, cv.getNumberValue(), 0.0);
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.