Search in sources :

Example 1 with XSSFFormulaEvaluator

use of org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator 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)

Example 2 with XSSFFormulaEvaluator

use of org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator in project poi by apache.

the class TestProper method testValidXSSF.

@Test
public void testValidXSSF() {
    XSSFWorkbook wb = new XSSFWorkbook();
    evaluator = new XSSFFormulaEvaluator(wb);
    confirm(wb);
}
Also used : XSSFFormulaEvaluator(org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Test(org.junit.Test)

Example 3 with XSSFFormulaEvaluator

use of org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator in project poi by apache.

the class ConditionalFormattingEvalTest method openWB.

@Before
public void openWB() {
    wb = XSSFTestDataSamples.openSampleWorkbook("ConditionalFormattingSamples.xlsx");
    formulaEval = new XSSFFormulaEvaluator(wb);
    cfe = new ConditionalFormattingEvaluator(wb, formulaEval);
}
Also used : XSSFFormulaEvaluator(org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator) ConditionalFormattingEvaluator(org.apache.poi.ss.formula.ConditionalFormattingEvaluator) Before(org.junit.Before)

Aggregations

XSSFFormulaEvaluator (org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 Test (org.junit.Test)2 ConditionalFormattingEvaluator (org.apache.poi.ss.formula.ConditionalFormattingEvaluator)1 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)1 Row (org.apache.poi.ss.usermodel.Row)1 AreaReference (org.apache.poi.ss.util.AreaReference)1 CellReference (org.apache.poi.ss.util.CellReference)1 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)1 XSSFTable (org.apache.poi.xssf.usermodel.XSSFTable)1 Before (org.junit.Before)1