Search in sources :

Example 26 with FormulaEvaluator

use of org.apache.poi.ss.usermodel.FormulaEvaluator in project poi by apache.

the class TestExcelAntWorkbookUtil method testGetEvaluatorXLSXWithFunction.

public void testGetEvaluatorXLSXWithFunction() {
    fixture = new ExcelAntWorkbookUtilTestHelper(BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx");
    fixture.addFunction("h2_ZFactor", new CalculateMortgageFunction());
    FormulaEvaluator evaluator = fixture.getEvaluator(BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx");
    assertNotNull(evaluator);
}
Also used : CalculateMortgageFunction(org.apache.poi.ss.examples.formula.CalculateMortgageFunction) FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator)

Example 27 with FormulaEvaluator

use of org.apache.poi.ss.usermodel.FormulaEvaluator in project poi by apache.

the class TestExcelAntWorkbookUtil method testGetEvaluator.

public void testGetEvaluator() {
    fixture = new ExcelAntWorkbookUtilTestHelper(mortgageCalculatorFileName);
    FormulaEvaluator evaluator = fixture.getEvaluator(mortgageCalculatorFileName);
    assertNotNull(evaluator);
}
Also used : FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator)

Example 28 with FormulaEvaluator

use of org.apache.poi.ss.usermodel.FormulaEvaluator in project poi by apache.

the class TestExcelAntWorkbookUtil method testGetEvaluatorWithUDF.

public void testGetEvaluatorWithUDF() {
    fixture = new ExcelAntWorkbookUtilTestHelper(mortgageCalculatorFileName);
    fixture.addFunction("h2_ZFactor", new CalculateMortgageFunction());
    FormulaEvaluator evaluator = fixture.getEvaluator(mortgageCalculatorFileName);
    assertNotNull(evaluator);
}
Also used : CalculateMortgageFunction(org.apache.poi.ss.examples.formula.CalculateMortgageFunction) FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator)

Example 29 with FormulaEvaluator

use of org.apache.poi.ss.usermodel.FormulaEvaluator in project poi by apache.

the class TestExcelAntWorkbookUtil method testGetEvaluatorXLSX.

public void testGetEvaluatorXLSX() {
    fixture = new ExcelAntWorkbookUtilTestHelper(BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx");
    FormulaEvaluator evaluator = fixture.getEvaluator(BuildFileTest.getDataDir() + "/spreadsheet/sample.xlsx");
    assertNotNull(evaluator);
}
Also used : FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator)

Example 30 with FormulaEvaluator

use of org.apache.poi.ss.usermodel.FormulaEvaluator in project poi by apache.

the class TestStructuredReferences method testTableFormulas.

@Test
public void testTableFormulas() throws Exception {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx");
    try {
        final FormulaEvaluator eval = new XSSFFormulaEvaluator(wb);
        final XSSFSheet tableSheet = wb.getSheet("Table");
        final XSSFSheet formulaSheet = wb.getSheet("Formulas");
        confirm(eval, tableSheet.getRow(5).getCell(0), 49);
        confirm(eval, formulaSheet.getRow(0).getCell(0), 209);
        confirm(eval, formulaSheet.getRow(1).getCell(0), "one");
        // test changing a table value, to see if the caches are properly cleared
        // Issue 59814
        // this test passes before the fix for 59814
        tableSheet.getRow(1).getCell(1).setCellValue("ONEA");
        confirm(eval, formulaSheet.getRow(1).getCell(0), "ONEA");
        // test adding a row to a table, issue 59814
        Row newRow = tableSheet.getRow(7);
        if (newRow == null)
            newRow = tableSheet.createRow(7);
        newRow.createCell(0, CellType.FORMULA).setCellFormula("\\_Prime.1[[#This Row],[@Number]]*\\_Prime.1[[#This Row],[@Number]]");
        newRow.createCell(1, CellType.STRING).setCellValue("thirteen");
        newRow.createCell(2, CellType.NUMERIC).setCellValue(13);
        // update Table
        final XSSFTable table = wb.getTable("\\_Prime.1");
        final AreaReference newArea = new AreaReference(table.getStartCellReference(), new CellReference(table.getEndRowIndex() + 1, table.getEndColIndex()));
        String newAreaStr = newArea.formatAsString();
        table.getCTTable().setRef(newAreaStr);
        table.getCTTable().getAutoFilter().setRef(newAreaStr);
        table.updateHeaders();
        table.updateReferences();
        // these fail before the fix for 59814
        confirm(eval, tableSheet.getRow(7).getCell(0), 13 * 13);
        confirm(eval, formulaSheet.getRow(0).getCell(0), 209 + 13 * 13);
    } finally {
        wb.close();
    }
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) XSSFFormulaEvaluator(org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) CellReference(org.apache.poi.ss.util.CellReference) XSSFTable(org.apache.poi.xssf.usermodel.XSSFTable) XSSFFormulaEvaluator(org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator) FormulaEvaluator(org.apache.poi.ss.usermodel.FormulaEvaluator) Test(org.junit.Test)

Aggregations

FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)55 Cell (org.apache.poi.ss.usermodel.Cell)39 Test (org.junit.Test)34 Workbook (org.apache.poi.ss.usermodel.Workbook)30 Sheet (org.apache.poi.ss.usermodel.Sheet)28 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)20 Row (org.apache.poi.ss.usermodel.Row)13 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)12 CellValue (org.apache.poi.ss.usermodel.CellValue)11 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)8 CellReference (org.apache.poi.ss.util.CellReference)7 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)6 BaseTestFormulaEvaluator (org.apache.poi.ss.usermodel.BaseTestFormulaEvaluator)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)3 DecimalFormat (java.text.DecimalFormat)2 ArrayList (java.util.ArrayList)2 InternalSheet (org.apache.poi.hssf.model.InternalSheet)2 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)2