use of org.apache.poi.ss.formula.ptg.ArrayPtg in project poi by apache.
the class TestFormulaParser method testParseStringElementInArray.
@Test
public void testParseStringElementInArray() {
Ptg[] ptgs;
ptgs = parseFormula("MAX({\"5\"},3)");
confirmTokenClasses(ptgs, ArrayPtg.class, IntPtg.class, FuncVarPtg.class);
Object element = ((ArrayPtg) ptgs[0]).getTokenArrayValues()[0][0];
if (element instanceof UnicodeString) {
// this would cause ClassCastException below
fail("Wrong encoding of array element value");
}
assertEquals(String.class, element.getClass());
// make sure the formula encodes OK
int encSize = Ptg.getEncodedSize(ptgs);
byte[] data = new byte[encSize];
Ptg.serializePtgs(ptgs, data, 0);
byte[] expData = HexRead.readFromString(// tArray
"20 00 00 00 00 00 00 00 " + // tInt(3)
"1E 03 00 " + // tFuncVar(MAX) 2-arg
"42 02 07 00 " + // Array data: 1 col, 1 row
"00 00 00 " + // elem (type=string, len=1, "5")
"02 01 00 00 35");
assertArrayEquals(expData, data);
int initSize = Ptg.getEncodedSizeWithoutArrayData(ptgs);
Ptg[] ptgs2 = Ptg.readTokens(initSize, new LittleEndianByteArrayInputStream(data));
confirmTokenClasses(ptgs2, ArrayPtg.class, IntPtg.class, FuncVarPtg.class);
}
use of org.apache.poi.ss.formula.ptg.ArrayPtg in project poi by apache.
the class FormulaParser method parseArray.
private ParseNode parseArray() {
List<Object[]> rowsData = new ArrayList<Object[]>();
while (true) {
Object[] singleRowData = parseArrayRow();
rowsData.add(singleRowData);
if (look == '}') {
break;
}
if (look != ';') {
throw expected("'}' or ';'");
}
Match(';');
}
int nRows = rowsData.size();
Object[][] values2d = new Object[nRows][];
rowsData.toArray(values2d);
int nColumns = values2d[0].length;
checkRowLengths(values2d, nColumns);
return new ParseNode(new ArrayPtg(values2d));
}
use of org.apache.poi.ss.formula.ptg.ArrayPtg in project poi by apache.
the class TestNameRecord method assert_bug50244.
private void assert_bug50244(NameRecord nr) {
assertEquals("wDataGruppeSerie.", nr.getNameText());
Ptg[] ptg = nr.getNameDefinition();
assertEquals(1, ptg.length);
ArrayPtg arr = (ArrayPtg) ptg[0];
assertEquals(696, arr.getRowCount());
assertEquals(1, arr.getColumnCount());
Object[][] vals = arr.getTokenArrayValues();
assertEquals("1.T20.001", vals[0][0]);
assertEquals("1.T20.010", vals[vals.length - 1][0]);
}
use of org.apache.poi.ss.formula.ptg.ArrayPtg in project poi by apache.
the class TestFormulaParser method testParseArray.
@Test
public void testParseArray() {
Ptg[] ptgs;
ptgs = parseFormula("mode({1,2,2,#REF!;FALSE,3,3,2})");
confirmTokenClasses(ptgs, ArrayPtg.class, FuncVarPtg.class);
assertEquals("{1,2,2,#REF!;FALSE,3,3,2}", ptgs[0].toFormulaString());
ArrayPtg aptg = (ArrayPtg) ptgs[0];
Object[][] values = aptg.getTokenArrayValues();
assertEquals(ErrorConstant.valueOf(FormulaError.REF.getCode()), values[0][3]);
assertEquals(Boolean.FALSE, values[1][0]);
}
Aggregations