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();
}
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);
}
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();
}
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();
}
Aggregations