| Method from org.apache.poi.hssf.record.formula.ArrayPtg Detail: |
public Object clone() {
ArrayPtg ptg = (ArrayPtg) super.clone();
ptg.field_1_reserved = (byte[]) field_1_reserved.clone();
ptg.token_3_arrayValues = (Object[]) token_3_arrayValues.clone();
return ptg;
}
|
public short getColumnCount() {
return token_1_columns;
}
|
public byte getDefaultOperandClass() {
return Ptg.CLASS_ARRAY;
}
|
public short getRowCount() {
return token_2_rows;
}
|
public int getSize() {
int size = 1+7+1+2;
size += ConstantValueParser.getEncodedSize(token_3_arrayValues);
return size;
}
This size includes the size of the array Ptg plus the Array Ptg Token value size |
public Object[] getTokenArrayValues() {
return (Object[]) token_3_arrayValues.clone();
}
|
int getValueIndex(int colIx,
int rowIx) {
if(colIx < 0 || colIx >= token_1_columns) {
throw new IllegalArgumentException("Specified colIx (" + colIx
+ ") is outside the allowed range (0.." + (token_1_columns-1) + ")");
}
if(rowIx < 0 || rowIx >= token_2_rows) {
throw new IllegalArgumentException("Specified rowIx (" + rowIx
+ ") is outside the allowed range (0.." + (token_2_rows-1) + ")");
}
return rowIx + token_2_rows * colIx;
}
Note - (2D) array elements are stored column by column |
public boolean isBaseToken() {
return false;
}
|
public void readTokenValues(RecordInputStream in) {
short nColumns = in.readUByte();
short nRows = in.readShort();
//The token_1_columns and token_2_rows do not follow the documentation.
//The number of physical rows and columns is actually +1 of these values.
//Which is not explicitly documented.
nColumns++;
nRows++;
token_1_columns = nColumns;
token_2_rows = nRows;
int totalCount = nRows * nColumns;
token_3_arrayValues = ConstantValueParser.parse(in, totalCount);
}
Read in the actual token (array) values. This occurs
AFTER the last Ptg in the expression.
See page 304-305 of Excel97-2007BinaryFileFormat(xls)Specification.pdf |
public String toFormulaString(HSSFWorkbook book) {
StringBuffer b = new StringBuffer();
b.append("{");
for (int x=0;x< getColumnCount();x++) {
if (x > 0) {
b.append(";");
}
for (int y=0;y< getRowCount();y++) {
if (y > 0) {
b.append(",");
}
Object o = token_3_arrayValues[getValueIndex(x, y)];
b.append(getConstantText(o));
}
}
b.append("}");
return b.toString();
}
|
public String toString() {
StringBuffer buffer = new StringBuffer("[ArrayPtg]\n");
buffer.append("columns = ").append(getColumnCount()).append("\n");
buffer.append("rows = ").append(getRowCount()).append("\n");
for (int x=0;x< getColumnCount();x++) {
for (int y=0;y< getRowCount();y++) {
Object o = token_3_arrayValues[getValueIndex(x, y)];
buffer.append("[").append(x).append("][").append(y).append("] = ").append(o).append("\n");
}
}
return buffer.toString();
}
|
public void writeBytes(byte[] data,
int offset) {
LittleEndian.putByte(data, offset + 0, sid + getPtgClass());
System.arraycopy(field_1_reserved, 0, data, offset+1, RESERVED_FIELD_LEN);
}
|
public int writeTokenValueBytes(byte[] data,
int offset) {
LittleEndian.putByte(data, offset + 0, token_1_columns-1);
LittleEndian.putShort(data, offset + 1, (short)(token_2_rows-1));
ConstantValueParser.encode(data, offset + 3, token_3_arrayValues);
return 3 + ConstantValueParser.getEncodedSize(token_3_arrayValues);
}
|