Search in sources :

Example 6 with HSSFName

use of org.apache.poi.hssf.usermodel.HSSFName in project poi by apache.

the class TestNameRecord method testFormulaRelAbs_bug46174.

public void testFormulaRelAbs_bug46174() throws IOException {
    // perhaps this testcase belongs on TestHSSFName
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFName name = wb.createName();
    wb.createSheet("Sheet1");
    name.setNameName("test");
    name.setRefersToFormula("Sheet1!$B$3");
    if (name.getRefersToFormula().equals("Sheet1!B3")) {
        fail("Identified bug 46174");
    }
    assertEquals("Sheet1!$B$3", name.getRefersToFormula());
    wb.close();
}
Also used : HSSFName(org.apache.poi.hssf.usermodel.HSSFName) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 7 with HSSFName

use of org.apache.poi.hssf.usermodel.HSSFName in project poi by apache.

the class TestFormulaParserEval method testWithNamedRange.

public void testWithNamedRange() {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet s = workbook.createSheet("Foo");
    s.createRow(0).createCell(0).setCellValue(1.1);
    s.createRow(1).createCell(0).setCellValue(2.3);
    s.createRow(2).createCell(2).setCellValue(3.1);
    HSSFName name = workbook.createName();
    name.setNameName("testName");
    name.setRefersToFormula("A1:A2");
    confirmParseFormula(workbook);
    // Now make it a single cell
    name.setRefersToFormula("C3");
    confirmParseFormula(workbook);
    // And make it non-contiguous
    // using area unions
    name.setRefersToFormula("A1:A2,C3");
    confirmParseFormula(workbook);
}
Also used : HSSFName(org.apache.poi.hssf.usermodel.HSSFName) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 8 with HSSFName

use of org.apache.poi.hssf.usermodel.HSSFName in project poi by apache.

the class TestFormulaParser method testBackSlashInNames.

/** Named ranges with backslashes, e.g. 'POI\\2009' */
@Test
public void testBackSlashInNames() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFName name = wb.createName();
    name.setNameName("POI\\2009");
    name.setRefersToFormula("Sheet1!$A$1");
    HSSFSheet sheet = wb.createSheet();
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell_C1 = row.createCell(2);
    cell_C1.setCellFormula("POI\\2009");
    assertEquals("POI\\2009", cell_C1.getCellFormula());
    HSSFCell cell_D1 = row.createCell(2);
    cell_D1.setCellFormula("NOT(POI\\2009=\"3.5-final\")");
    assertEquals("NOT(POI\\2009=\"3.5-final\")", cell_D1.getCellFormula());
    wb.close();
}
Also used : TestHSSFName(org.apache.poi.hssf.usermodel.TestHSSFName) HSSFName(org.apache.poi.hssf.usermodel.HSSFName) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 9 with HSSFName

use of org.apache.poi.hssf.usermodel.HSSFName in project poi by apache.

the class TestFormulaParser method testNamedRangeThatLooksLikeCell.

@Test
public void testNamedRangeThatLooksLikeCell() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Sheet1");
    HSSFName name = wb.createName();
    name.setRefersToFormula("Sheet1!B1");
    name.setNameName("pfy1");
    Ptg[] ptgs;
    try {
        ptgs = HSSFFormulaParser.parse("count(pfy1)", wb);
    } catch (IllegalArgumentException e) {
        if (e.getMessage().equals("Specified colIx (1012) is out of range")) {
            fail("Identified bug 45354");
        }
        wb.close();
        throw e;
    }
    confirmTokenClasses(ptgs, NamePtg.class, FuncVarPtg.class);
    HSSFCell cell = sheet.createRow(0).createCell(0);
    cell.setCellFormula("count(pfy1)");
    assertEquals("COUNT(pfy1)", cell.getCellFormula());
    try {
        cell.setCellFormula("count(pf1)");
        fail("Expected formula parse execption");
    } catch (FormulaParseException e) {
        confirmParseException(e, "Specified named range 'pf1' does not exist in the current workbook.");
    }
    // plain cell ref, col is in range
    cell.setCellFormula("count(fp1)");
    wb.close();
}
Also used : FormulaParseException(org.apache.poi.ss.formula.FormulaParseException) TestHSSFName(org.apache.poi.hssf.usermodel.TestHSSFName) HSSFName(org.apache.poi.hssf.usermodel.HSSFName) NumberPtg(org.apache.poi.ss.formula.ptg.NumberPtg) ArrayPtg(org.apache.poi.ss.formula.ptg.ArrayPtg) AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg) PercentPtg(org.apache.poi.ss.formula.ptg.PercentPtg) RangePtg(org.apache.poi.ss.formula.ptg.RangePtg) AddPtg(org.apache.poi.ss.formula.ptg.AddPtg) EqualPtg(org.apache.poi.ss.formula.ptg.EqualPtg) UnaryMinusPtg(org.apache.poi.ss.formula.ptg.UnaryMinusPtg) NameXPtg(org.apache.poi.ss.formula.ptg.NameXPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) DividePtg(org.apache.poi.ss.formula.ptg.DividePtg) GreaterThanPtg(org.apache.poi.ss.formula.ptg.GreaterThanPtg) MultiplyPtg(org.apache.poi.ss.formula.ptg.MultiplyPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) ErrPtg(org.apache.poi.ss.formula.ptg.ErrPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) NamePtg(org.apache.poi.ss.formula.ptg.NamePtg) MemAreaPtg(org.apache.poi.ss.formula.ptg.MemAreaPtg) ConcatPtg(org.apache.poi.ss.formula.ptg.ConcatPtg) UnaryPlusPtg(org.apache.poi.ss.formula.ptg.UnaryPlusPtg) BoolPtg(org.apache.poi.ss.formula.ptg.BoolPtg) IntersectionPtg(org.apache.poi.ss.formula.ptg.IntersectionPtg) AbstractFunctionPtg(org.apache.poi.ss.formula.ptg.AbstractFunctionPtg) IntPtg(org.apache.poi.ss.formula.ptg.IntPtg) UnionPtg(org.apache.poi.ss.formula.ptg.UnionPtg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg) SubtractPtg(org.apache.poi.ss.formula.ptg.SubtractPtg) FuncPtg(org.apache.poi.ss.formula.ptg.FuncPtg) MissingArgPtg(org.apache.poi.ss.formula.ptg.MissingArgPtg) MemFuncPtg(org.apache.poi.ss.formula.ptg.MemFuncPtg) PowerPtg(org.apache.poi.ss.formula.ptg.PowerPtg) AreaPtg(org.apache.poi.ss.formula.ptg.AreaPtg) ParenthesisPtg(org.apache.poi.ss.formula.ptg.ParenthesisPtg) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Aggregations

HSSFName (org.apache.poi.hssf.usermodel.HSSFName)9 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)9 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)5 TestHSSFName (org.apache.poi.hssf.usermodel.TestHSSFName)4 Test (org.junit.Test)4 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)3 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)3 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)3 MemFuncPtg (org.apache.poi.ss.formula.ptg.MemFuncPtg)3 Ptg (org.apache.poi.ss.formula.ptg.Ptg)3 NameRecord (org.apache.poi.hssf.record.NameRecord)2 FormulaParseException (org.apache.poi.ss.formula.FormulaParseException)2 AbstractFunctionPtg (org.apache.poi.ss.formula.ptg.AbstractFunctionPtg)2 AddPtg (org.apache.poi.ss.formula.ptg.AddPtg)2 AreaPtg (org.apache.poi.ss.formula.ptg.AreaPtg)2 ArrayPtg (org.apache.poi.ss.formula.ptg.ArrayPtg)2 AttrPtg (org.apache.poi.ss.formula.ptg.AttrPtg)2 BoolPtg (org.apache.poi.ss.formula.ptg.BoolPtg)2 ConcatPtg (org.apache.poi.ss.formula.ptg.ConcatPtg)2 DividePtg (org.apache.poi.ss.formula.ptg.DividePtg)2