use of org.apache.poi.ss.formula.ptg.MemFuncPtg in project poi by apache.
the class TestFormulaParser method testRange_bug46643.
@Test
public void testRange_bug46643() throws IOException {
String formula = "Sheet1!A1:Sheet1!B3";
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet("Sheet1");
Ptg[] ptgs = FormulaParser.parse(formula, HSSFEvaluationWorkbook.create(wb), FormulaType.CELL, -1, -1);
if (ptgs.length == 3) {
confirmTokenClasses(ptgs, Ref3DPtg.class, Ref3DPtg.class, RangePtg.class);
fail("Identified bug 46643");
}
confirmTokenClasses(ptgs, MemFuncPtg.class, Ref3DPtg.class, Ref3DPtg.class, RangePtg.class);
MemFuncPtg mf = (MemFuncPtg) ptgs[0];
assertEquals(15, mf.getLenRefSubexpression());
wb.close();
}
use of org.apache.poi.ss.formula.ptg.MemFuncPtg in project poi by apache.
the class TestFormulaParser method testIntersection.
@Test
public void testIntersection() throws IOException {
String formula = "Sheet1!$B$2:$C$3 OFFSET(Sheet1!$E$2:$E$4, 1,Sheet1!$A$1) Sheet1!$D$6";
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet("Sheet1");
Ptg[] ptgs = FormulaParser.parse(formula, HSSFEvaluationWorkbook.create(wb), FormulaType.CELL, -1);
confirmTokenClasses(ptgs, // TODO - AttrPtg.class, // Excel prepends this
MemFuncPtg.class, Area3DPtg.class, Area3DPtg.class, IntPtg.class, Ref3DPtg.class, FuncVarPtg.class, IntersectionPtg.class, Ref3DPtg.class, IntersectionPtg.class);
MemFuncPtg mf = (MemFuncPtg) ptgs[0];
assertEquals(45, mf.getLenRefSubexpression());
// This used to be an error but now parses. Union has the same behaviour.
confirmTokenClasses("1 2", MemAreaPtg.class, IntPtg.class, IntPtg.class, IntersectionPtg.class);
wb.close();
}
use of org.apache.poi.ss.formula.ptg.MemFuncPtg in project poi by apache.
the class TestFormulaParser method testUnion.
@Test
public void testUnion() throws IOException {
String formula = "Sheet1!$B$2:$C$3,OFFSET(Sheet1!$E$2:$E$4,1,Sheet1!$A$1),Sheet1!$D$6";
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet("Sheet1");
Ptg[] ptgs = FormulaParser.parse(formula, HSSFEvaluationWorkbook.create(wb), FormulaType.CELL, -1);
confirmTokenClasses(ptgs, // TODO - AttrPtg.class, // Excel prepends this
MemFuncPtg.class, Area3DPtg.class, Area3DPtg.class, IntPtg.class, Ref3DPtg.class, FuncVarPtg.class, UnionPtg.class, Ref3DPtg.class, UnionPtg.class);
MemFuncPtg mf = (MemFuncPtg) ptgs[0];
assertEquals(45, mf.getLenRefSubexpression());
// We don't check the type of the operands.
confirmTokenClasses("1,2", MemAreaPtg.class, IntPtg.class, IntPtg.class, UnionPtg.class);
wb.close();
}
use of org.apache.poi.ss.formula.ptg.MemFuncPtg in project poi by apache.
the class HSSFSheet method setRepeatingRowsAndColumns.
private void setRepeatingRowsAndColumns(CellRangeAddress rowDef, CellRangeAddress colDef) {
int sheetIndex = _workbook.getSheetIndex(this);
int maxRowIndex = SpreadsheetVersion.EXCEL97.getLastRowIndex();
int maxColIndex = SpreadsheetVersion.EXCEL97.getLastColumnIndex();
int col1 = -1;
int col2 = -1;
int row1 = -1;
int row2 = -1;
if (rowDef != null) {
row1 = rowDef.getFirstRow();
row2 = rowDef.getLastRow();
if ((row1 == -1 && row2 != -1) || (row1 > row2) || (row1 < 0 || row1 > maxRowIndex) || (row2 < 0 || row2 > maxRowIndex)) {
throw new IllegalArgumentException("Invalid row range specification");
}
}
if (colDef != null) {
col1 = colDef.getFirstColumn();
col2 = colDef.getLastColumn();
if ((col1 == -1 && col2 != -1) || (col1 > col2) || (col1 < 0 || col1 > maxColIndex) || (col2 < 0 || col2 > maxColIndex)) {
throw new IllegalArgumentException("Invalid column range specification");
}
}
short externSheetIndex = _workbook.getWorkbook().checkExternSheet(sheetIndex);
boolean setBoth = rowDef != null && colDef != null;
boolean removeAll = rowDef == null && colDef == null;
HSSFName name = _workbook.getBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex);
if (removeAll) {
if (name != null) {
_workbook.removeName(name);
}
return;
}
if (name == null) {
name = _workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex);
}
List<Ptg> ptgList = new ArrayList<Ptg>();
if (setBoth) {
// 2 * Area3DPtg.SIZE + UnionPtg.SIZE
final int exprsSize = 2 * 11 + 1;
ptgList.add(new MemFuncPtg(exprsSize));
}
if (colDef != null) {
Area3DPtg colArea = new Area3DPtg(0, maxRowIndex, col1, col2, false, false, false, false, externSheetIndex);
ptgList.add(colArea);
}
if (rowDef != null) {
Area3DPtg rowArea = new Area3DPtg(row1, row2, 0, maxColIndex, false, false, false, false, externSheetIndex);
ptgList.add(rowArea);
}
if (setBoth) {
ptgList.add(UnionPtg.instance);
}
Ptg[] ptgs = new Ptg[ptgList.size()];
ptgList.toArray(ptgs);
name.setNameDefinition(ptgs);
HSSFPrintSetup printSetup = getPrintSetup();
printSetup.setValidSettings(false);
setActive(true);
}
Aggregations