Fix for bug 45091 - serialization of RefN~ tokens. Simplified Ptg class hierarchy
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@664220 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bade69a176
commit
8eaa48315f
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
<!-- Don't forget to update status.xml too! -->
|
<!-- Don't forget to update status.xml too! -->
|
||||||
<release version="3.1-final" date="2008-06-??">
|
<release version="3.1-final" date="2008-06-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">45091 - Fixed serialization of RefN~ tokens. Simplified Ptg class hierarchy</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45133 - Fixed OBJ Record (5Dh) to pad the sub-record data to a 4-byte boundary</action>
|
<action dev="POI-DEVELOPERS" type="fix">45133 - Fixed OBJ Record (5Dh) to pad the sub-record data to a 4-byte boundary</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45145 - Fixed Sheet to always enforce RowRecordsAggregate before ValueRecordsAggregate</action>
|
<action dev="POI-DEVELOPERS" type="fix">45145 - Fixed Sheet to always enforce RowRecordsAggregate before ValueRecordsAggregate</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45123 - Fixed SharedFormulaRecord.convertSharedFormulas() to propagate token operand classes</action>
|
<action dev="POI-DEVELOPERS" type="fix">45123 - Fixed SharedFormulaRecord.convertSharedFormulas() to propagate token operand classes</action>
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
<!-- Don't forget to update changes.xml too! -->
|
<!-- Don't forget to update changes.xml too! -->
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.1-final" date="2008-06-??">
|
<release version="3.1-final" date="2008-06-??">
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">45091 - Fixed serialization of RefN~ tokens. Simplified Ptg class hierarchy</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45133 - Fixed OBJ Record (5Dh) to pad the sub-record data to a 4-byte boundary</action>
|
<action dev="POI-DEVELOPERS" type="fix">45133 - Fixed OBJ Record (5Dh) to pad the sub-record data to a 4-byte boundary</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45145 - Fixed Sheet to always enforce RowRecordsAggregate before ValueRecordsAggregate</action>
|
<action dev="POI-DEVELOPERS" type="fix">45145 - Fixed Sheet to always enforce RowRecordsAggregate before ValueRecordsAggregate</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45123 - Fixed SharedFormulaRecord.convertSharedFormulas() to propagate token operand classes</action>
|
<action dev="POI-DEVELOPERS" type="fix">45123 - Fixed SharedFormulaRecord.convertSharedFormulas() to propagate token operand classes</action>
|
||||||
|
@ -274,7 +274,7 @@ public final class FormulaParser {
|
|||||||
boolean cellRef = CELL_REFERENCE_PATTERN.matcher(name).matches();
|
boolean cellRef = CELL_REFERENCE_PATTERN.matcher(name).matches();
|
||||||
|
|
||||||
if (cellRef) {
|
if (cellRef) {
|
||||||
return new ReferencePtg(name);
|
return new RefPtg(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < book.getNumberOfNames(); i++) {
|
for(int i = 0; i < book.getNumberOfNames(); i++) {
|
||||||
@ -392,7 +392,7 @@ public final class FormulaParser {
|
|||||||
SkipWhite();
|
SkipWhite();
|
||||||
if (isArgumentDelimiter(look)) {
|
if (isArgumentDelimiter(look)) {
|
||||||
if (missedPrevArg) {
|
if (missedPrevArg) {
|
||||||
temp.add(new ParseNode(new MissingArgPtg()));
|
temp.add(new ParseNode(MissingArgPtg.instance));
|
||||||
numArgs++;
|
numArgs++;
|
||||||
}
|
}
|
||||||
if (look == ')') {
|
if (look == ')') {
|
||||||
@ -425,7 +425,7 @@ public final class FormulaParser {
|
|||||||
}
|
}
|
||||||
Match('^');
|
Match('^');
|
||||||
ParseNode other = percentFactor();
|
ParseNode other = percentFactor();
|
||||||
result = new ParseNode(new PowerPtg(), result, other);
|
result = new ParseNode(PowerPtg.instance, result, other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +437,7 @@ public final class FormulaParser {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
Match('%');
|
Match('%');
|
||||||
result = new ParseNode(new PercentPtg(), result);
|
result = new ParseNode(PercentPtg.instance, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,15 +452,15 @@ public final class FormulaParser {
|
|||||||
return new ParseNode(parseErrorLiteral());
|
return new ParseNode(parseErrorLiteral());
|
||||||
case '-':
|
case '-':
|
||||||
Match('-');
|
Match('-');
|
||||||
return new ParseNode(new UnaryMinusPtg(), powerFactor());
|
return new ParseNode(UnaryMinusPtg.instance, powerFactor());
|
||||||
case '+':
|
case '+':
|
||||||
Match('+');
|
Match('+');
|
||||||
return new ParseNode(new UnaryPlusPtg(), powerFactor());
|
return new ParseNode(UnaryPlusPtg.instance, powerFactor());
|
||||||
case '(':
|
case '(':
|
||||||
Match('(');
|
Match('(');
|
||||||
ParseNode inside = comparisonExpression();
|
ParseNode inside = comparisonExpression();
|
||||||
Match(')');
|
Match(')');
|
||||||
return new ParseNode(new ParenthesisPtg(), inside);
|
return new ParseNode(ParenthesisPtg.instance, inside);
|
||||||
case '"':
|
case '"':
|
||||||
return new ParseNode(parseStringLiteral());
|
return new ParseNode(parseStringLiteral());
|
||||||
}
|
}
|
||||||
@ -632,11 +632,11 @@ public final class FormulaParser {
|
|||||||
switch(look) {
|
switch(look) {
|
||||||
case '*':
|
case '*':
|
||||||
Match('*');
|
Match('*');
|
||||||
operator = new MultiplyPtg();
|
operator = MultiplyPtg.instance;
|
||||||
break;
|
break;
|
||||||
case '/':
|
case '/':
|
||||||
Match('/');
|
Match('/');
|
||||||
operator = new DividePtg();
|
operator = DividePtg.instance;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return result; // finished with Term
|
return result; // finished with Term
|
||||||
@ -666,26 +666,26 @@ public final class FormulaParser {
|
|||||||
private Ptg getComparisonToken() {
|
private Ptg getComparisonToken() {
|
||||||
if(look == '=') {
|
if(look == '=') {
|
||||||
Match(look);
|
Match(look);
|
||||||
return new EqualPtg();
|
return EqualPtg.instance;
|
||||||
}
|
}
|
||||||
boolean isGreater = look == '>';
|
boolean isGreater = look == '>';
|
||||||
Match(look);
|
Match(look);
|
||||||
if(isGreater) {
|
if(isGreater) {
|
||||||
if(look == '=') {
|
if(look == '=') {
|
||||||
Match('=');
|
Match('=');
|
||||||
return new GreaterEqualPtg();
|
return GreaterEqualPtg.instance;
|
||||||
}
|
}
|
||||||
return new GreaterThanPtg();
|
return GreaterThanPtg.instance;
|
||||||
}
|
}
|
||||||
switch(look) {
|
switch(look) {
|
||||||
case '=':
|
case '=':
|
||||||
Match('=');
|
Match('=');
|
||||||
return new LessEqualPtg();
|
return LessEqualPtg.instance;
|
||||||
case '>':
|
case '>':
|
||||||
Match('>');
|
Match('>');
|
||||||
return new NotEqualPtg();
|
return NotEqualPtg.instance;
|
||||||
}
|
}
|
||||||
return new LessThanPtg();
|
return LessThanPtg.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -698,7 +698,7 @@ public final class FormulaParser {
|
|||||||
}
|
}
|
||||||
Match('&');
|
Match('&');
|
||||||
ParseNode other = additiveExpression();
|
ParseNode other = additiveExpression();
|
||||||
result = new ParseNode(new ConcatPtg(), result, other);
|
result = new ParseNode(ConcatPtg.instance, result, other);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -713,11 +713,11 @@ public final class FormulaParser {
|
|||||||
switch(look) {
|
switch(look) {
|
||||||
case '+':
|
case '+':
|
||||||
Match('+');
|
Match('+');
|
||||||
operator = new AddPtg();
|
operator = AddPtg.instance;
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
Match('-');
|
Match('-');
|
||||||
operator = new SubtractPtg();
|
operator = SubtractPtg.instance;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return result; // finished with additive expression
|
return result; // finished with additive expression
|
||||||
|
@ -557,7 +557,7 @@ public final class FormulaRecord
|
|||||||
if (field_8_parsed_expr != null)
|
if (field_8_parsed_expr != null)
|
||||||
size = field_8_parsed_expr.size();
|
size = field_8_parsed_expr.size();
|
||||||
for (int i=0; i< size; i++) {
|
for (int i=0; i< size; i++) {
|
||||||
Ptg ptg = (Ptg)((Ptg)field_8_parsed_expr.get(i)).clone();
|
Ptg ptg = ((Ptg)field_8_parsed_expr.get(i)).copy();
|
||||||
rec.field_8_parsed_expr.add(i, ptg);
|
rec.field_8_parsed_expr.add(i, ptg);
|
||||||
}
|
}
|
||||||
rec.value_data = value_data;
|
rec.value_data = value_data;
|
||||||
|
@ -737,7 +737,7 @@ public class NameRecord extends Record {
|
|||||||
}
|
}
|
||||||
// And then a union if we had more than one area
|
// And then a union if we had more than one area
|
||||||
if(refs.length > 1) {
|
if(refs.length > 1) {
|
||||||
ptg = new UnionPtg();
|
ptg = UnionPtg.instance;
|
||||||
field_13_name_definition.push(ptg);
|
field_13_name_definition.push(ptg);
|
||||||
this.setDefinitionTextLength( (short)(getDefinitionLength() + ptg.getSize()) );
|
this.setDefinitionTextLength( (short)(getDefinitionLength() + ptg.getSize()) );
|
||||||
}
|
}
|
||||||
|
@ -207,22 +207,10 @@ public final class SharedFormulaRecord extends Record {
|
|||||||
}
|
}
|
||||||
if (ptg instanceof RefNPtg) {
|
if (ptg instanceof RefNPtg) {
|
||||||
RefNPtg refNPtg = (RefNPtg)ptg;
|
RefNPtg refNPtg = (RefNPtg)ptg;
|
||||||
ptg = new ReferencePtg(fixupRelativeRow(formulaRow,refNPtg.getRow(),refNPtg.isRowRelative()),
|
ptg = new RefPtg(fixupRelativeRow(formulaRow,refNPtg.getRow(),refNPtg.isRowRelative()),
|
||||||
fixupRelativeColumn(formulaColumn,refNPtg.getColumn(),refNPtg.isColRelative()),
|
fixupRelativeColumn(formulaColumn,refNPtg.getColumn(),refNPtg.isColRelative()),
|
||||||
refNPtg.isRowRelative(),
|
refNPtg.isRowRelative(),
|
||||||
refNPtg.isColRelative());
|
refNPtg.isColRelative());
|
||||||
} else if (ptg instanceof RefNVPtg) {
|
|
||||||
RefNVPtg refNVPtg = (RefNVPtg)ptg;
|
|
||||||
ptg = new RefVPtg(fixupRelativeRow(formulaRow,refNVPtg.getRow(),refNVPtg.isRowRelative()),
|
|
||||||
fixupRelativeColumn(formulaColumn,refNVPtg.getColumn(),refNVPtg.isColRelative()),
|
|
||||||
refNVPtg.isRowRelative(),
|
|
||||||
refNVPtg.isColRelative());
|
|
||||||
} else if (ptg instanceof RefNAPtg) {
|
|
||||||
RefNAPtg refNAPtg = (RefNAPtg)ptg;
|
|
||||||
ptg = new RefAPtg( fixupRelativeRow(formulaRow,refNAPtg.getRow(),refNAPtg.isRowRelative()),
|
|
||||||
fixupRelativeColumn(formulaColumn,refNAPtg.getColumn(),refNAPtg.isColRelative()),
|
|
||||||
refNAPtg.isRowRelative(),
|
|
||||||
refNAPtg.isColRelative());
|
|
||||||
} else if (ptg instanceof AreaNPtg) {
|
} else if (ptg instanceof AreaNPtg) {
|
||||||
AreaNPtg areaNPtg = (AreaNPtg)ptg;
|
AreaNPtg areaNPtg = (AreaNPtg)ptg;
|
||||||
ptg = new AreaPtg(fixupRelativeRow(formulaRow,areaNPtg.getFirstRow(),areaNPtg.isFirstRowRelative()),
|
ptg = new AreaPtg(fixupRelativeRow(formulaRow,areaNPtg.getFirstRow(),areaNPtg.isFirstRowRelative()),
|
||||||
@ -233,26 +221,6 @@ public final class SharedFormulaRecord extends Record {
|
|||||||
areaNPtg.isLastRowRelative(),
|
areaNPtg.isLastRowRelative(),
|
||||||
areaNPtg.isFirstColRelative(),
|
areaNPtg.isFirstColRelative(),
|
||||||
areaNPtg.isLastColRelative());
|
areaNPtg.isLastColRelative());
|
||||||
} else if (ptg instanceof AreaNVPtg) {
|
|
||||||
AreaNVPtg areaNVPtg = (AreaNVPtg)ptg;
|
|
||||||
ptg = new AreaVPtg(fixupRelativeRow(formulaRow,areaNVPtg.getFirstRow(),areaNVPtg.isFirstRowRelative()),
|
|
||||||
fixupRelativeRow(formulaRow,areaNVPtg.getLastRow(),areaNVPtg.isLastRowRelative()),
|
|
||||||
fixupRelativeColumn(formulaColumn,areaNVPtg.getFirstColumn(),areaNVPtg.isFirstColRelative()),
|
|
||||||
fixupRelativeColumn(formulaColumn,areaNVPtg.getLastColumn(),areaNVPtg.isLastColRelative()),
|
|
||||||
areaNVPtg.isFirstRowRelative(),
|
|
||||||
areaNVPtg.isLastRowRelative(),
|
|
||||||
areaNVPtg.isFirstColRelative(),
|
|
||||||
areaNVPtg.isLastColRelative());
|
|
||||||
} else if (ptg instanceof AreaNAPtg) {
|
|
||||||
AreaNAPtg areaNAPtg = (AreaNAPtg)ptg;
|
|
||||||
ptg = new AreaAPtg(fixupRelativeRow(formulaRow,areaNAPtg.getFirstRow(),areaNAPtg.isFirstRowRelative()),
|
|
||||||
fixupRelativeRow(formulaRow,areaNAPtg.getLastRow(),areaNAPtg.isLastRowRelative()),
|
|
||||||
fixupRelativeColumn(formulaColumn,areaNAPtg.getFirstColumn(),areaNAPtg.isFirstColRelative()),
|
|
||||||
fixupRelativeColumn(formulaColumn,areaNAPtg.getLastColumn(),areaNAPtg.isLastColRelative()),
|
|
||||||
areaNAPtg.isFirstRowRelative(),
|
|
||||||
areaNAPtg.isLastRowRelative(),
|
|
||||||
areaNAPtg.isFirstColRelative(),
|
|
||||||
areaNAPtg.isLastColRelative());
|
|
||||||
}
|
}
|
||||||
if (!ptg.isBaseToken()) {
|
if (!ptg.isBaseToken()) {
|
||||||
ptg.setClass(originalOperandClass);
|
ptg.setClass(originalOperandClass);
|
||||||
|
@ -56,12 +56,6 @@ public abstract class AbstractFunctionPtg extends OperationPtg {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getType() {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public short getFunctionIndex() {
|
public short getFunctionIndex() {
|
||||||
return field_2_fnc_index;
|
return field_2_fnc_index;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,6 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Addition operator PTG the "+" binomial operator. If you need more
|
* Addition operator PTG the "+" binomial operator. If you need more
|
||||||
* explanation than that then well...We really can't help you here.
|
* explanation than that then well...We really can't help you here.
|
||||||
@ -27,50 +24,24 @@ import org.apache.poi.hssf.record.RecordInputStream;
|
|||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
public final class AddPtg extends ValueOperatorPtg {
|
public final class AddPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x03;
|
public final static byte sid = 0x03;
|
||||||
|
|
||||||
private final static String ADD = "+";
|
private final static String ADD = "+";
|
||||||
|
|
||||||
/** Creates new AddPtg */
|
public static final ValueOperatorPtg instance = new AddPtg();
|
||||||
|
|
||||||
public AddPtg()
|
private AddPtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddPtg(RecordInputStream in)
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumberOfOperands() {
|
||||||
public void writeBytes(byte [] array, int offset)
|
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Implementation of method from Ptg */
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return "+";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** implementation of method from OperationsPtg*/
|
/** implementation of method from OperationsPtg*/
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
@ -80,9 +51,4 @@ public final class AddPtg extends ValueOperatorPtg {
|
|||||||
buffer.append(operands[ 1 ]);
|
buffer.append(operands[ 1 ]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new AddPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ public class Area3DPtg extends OperandPtg implements AreaI {
|
|||||||
|
|
||||||
public void writeBytes( byte[] array, int offset )
|
public void writeBytes( byte[] array, int offset )
|
||||||
{
|
{
|
||||||
array[0 + offset] = (byte) ( sid + ptgClass );
|
array[0 + offset] = (byte) ( sid + getPtgClass() );
|
||||||
LittleEndian.putShort( array, 1 + offset, getExternSheetIndex() );
|
LittleEndian.putShort( array, 1 + offset, getExternSheetIndex() );
|
||||||
LittleEndian.putShort( array, 3 + offset, (short)getFirstRow() );
|
LittleEndian.putShort( array, 3 + offset, (short)getFirstRow() );
|
||||||
LittleEndian.putShort( array, 5 + offset, (short)getLastRow() );
|
LittleEndian.putShort( array, 5 + offset, (short)getLastRow() );
|
||||||
@ -280,24 +280,10 @@ public class Area3DPtg extends OperandPtg implements AreaI {
|
|||||||
return retval.toString();
|
return retval.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getDefaultOperandClass()
|
public byte getDefaultOperandClass() {
|
||||||
{
|
|
||||||
return Ptg.CLASS_REF;
|
return Ptg.CLASS_REF;
|
||||||
}
|
}
|
||||||
|
// TODO - one junit relies on this. remove
|
||||||
public Object clone()
|
|
||||||
{
|
|
||||||
Area3DPtg ptg = new Area3DPtg();
|
|
||||||
ptg.field_1_index_extern_sheet = field_1_index_extern_sheet;
|
|
||||||
ptg.field_2_first_row = field_2_first_row;
|
|
||||||
ptg.field_3_last_row = field_3_last_row;
|
|
||||||
ptg.field_4_first_column = field_4_first_column;
|
|
||||||
ptg.field_5_last_column = field_5_last_column;
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public boolean equals( Object o )
|
public boolean equals( Object o )
|
||||||
{
|
{
|
||||||
if ( this == o ) return true;
|
if ( this == o ) return true;
|
||||||
@ -313,18 +299,4 @@ public class Area3DPtg extends OperandPtg implements AreaI {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
// TODO - hashCode seems to be unused
|
|
||||||
int result;
|
|
||||||
result = (int) field_1_index_extern_sheet;
|
|
||||||
result = 29 * result + (int) field_2_first_row;
|
|
||||||
result = 29 * result + (int) field_3_last_row;
|
|
||||||
result = 29 * result + (int) field_4_first_column;
|
|
||||||
result = 29 * result + (int) field_5_last_column;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* AreaPtg.java
|
|
||||||
*
|
|
||||||
* Created on November 17, 2001, 9:30 PM
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
|
||||||
import org.apache.poi.util.BitField;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
import org.apache.poi.hssf.util.AreaReference;
|
|
||||||
import org.apache.poi.hssf.util.CellReference;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies a rectangular area of cells A1:A4 for instance.
|
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
|
||||||
*/
|
|
||||||
|
|
||||||
public final class AreaAPtg extends AreaPtg {
|
|
||||||
public final static short sid = 0x65;
|
|
||||||
|
|
||||||
protected AreaAPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaAPtg(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
|
|
||||||
super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaAPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
super(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAreaPtgName() {
|
|
||||||
return "AreaAPtg";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
AreaAPtg ptg = new AreaAPtg();
|
|
||||||
ptg.setFirstRow(getFirstRow());
|
|
||||||
ptg.setLastRow(getLastRow());
|
|
||||||
ptg.setFirstColumnRaw(getFirstColumnRaw());
|
|
||||||
ptg.setLastColumnRaw(getLastColumnRaw());
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
|
@ -17,73 +17,40 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
|
||||||
import org.apache.poi.util.BitField;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AreaErr - handles deleted cell area references.
|
* AreaErr - handles deleted cell area references.
|
||||||
*
|
*
|
||||||
* @author Daniel Noll (daniel at nuix dot com dot au)
|
* @author Daniel Noll (daniel at nuix dot com dot au)
|
||||||
*/
|
*/
|
||||||
public class AreaErrPtg extends AreaPtg
|
public final class AreaErrPtg extends OperandPtg {
|
||||||
{
|
|
||||||
public final static byte sid = 0x2b;
|
public final static byte sid = 0x2b;
|
||||||
|
|
||||||
private AreaErrPtg()
|
public AreaErrPtg(RecordInputStream in) {
|
||||||
{
|
// 8 bytes unused:
|
||||||
//Required for clone methods
|
in.readInt();
|
||||||
super();
|
in.readInt();
|
||||||
}
|
|
||||||
|
|
||||||
public AreaErrPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
super(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
|
|
||||||
buffer.append("AreaErrPtg\n");
|
|
||||||
buffer.append("firstRow = " + getFirstRow()).append("\n");
|
|
||||||
buffer.append("lastRow = " + getLastRow()).append("\n");
|
|
||||||
buffer.append("firstCol = " + getFirstColumn()).append("\n");
|
|
||||||
buffer.append("lastCol = " + getLastColumn()).append("\n");
|
|
||||||
buffer.append("firstColRowRel= "
|
|
||||||
+ isFirstRowRelative()).append("\n");
|
|
||||||
buffer.append("lastColRowRel = "
|
|
||||||
+ isLastRowRelative()).append("\n");
|
|
||||||
buffer.append("firstColRel = " + isFirstColRelative()).append("\n");
|
|
||||||
buffer.append("lastColRel = " + isLastColRelative()).append("\n");
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset) {
|
public void writeBytes(byte [] array, int offset) {
|
||||||
super.writeBytes(array, offset);
|
array[offset] = (byte) (sid + getPtgClass());
|
||||||
array[offset] = (byte) (sid + ptgClass);
|
LittleEndian.putInt(array, offset+1, 0);
|
||||||
|
LittleEndian.putInt(array, offset+5, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
public String toFormulaString(HSSFWorkbook book) {
|
||||||
{
|
|
||||||
return "#REF!";
|
return "#REF!";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone()
|
public byte getDefaultOperandClass() {
|
||||||
{
|
return Ptg.CLASS_REF;
|
||||||
AreaErrPtg ptg = new AreaErrPtg();
|
}
|
||||||
ptg.setFirstRow(getFirstRow());
|
|
||||||
ptg.setFirstColumn(getFirstColumn());
|
public int getSize() {
|
||||||
ptg.setLastRow(getLastRow());
|
return 9;
|
||||||
ptg.setLastColumn(getLastColumn());
|
|
||||||
ptg.setFirstColRelative(isFirstColRelative());
|
|
||||||
ptg.setLastColRelative(isLastColRelative());
|
|
||||||
ptg.setFirstRowRelative(isFirstRowRelative());
|
|
||||||
ptg.setLastRowRelative(isLastRowRelative());
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies a rectangular area of cells A1:A4 for instance.
|
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
|
||||||
*/
|
|
||||||
|
|
||||||
public final class AreaNAPtg extends AreaPtg
|
|
||||||
{
|
|
||||||
public final static short sid = 0x6D;
|
|
||||||
|
|
||||||
protected AreaNAPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaNAPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
super(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAreaPtgName() {
|
|
||||||
return "AreaNAPtg";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,49 +15,22 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
/*
|
|
||||||
* AreaPtg.java
|
|
||||||
*
|
|
||||||
* Created on November 17, 2001, 9:30 PM
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
|
||||||
import org.apache.poi.util.BitField;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
import org.apache.poi.hssf.util.AreaReference;
|
|
||||||
import org.apache.poi.hssf.util.CellReference;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies a rectangular area of cells A1:A4 for instance.
|
* Specifies a rectangular area of cells A1:A4 for instance.
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
|
public final class AreaNPtg extends AreaPtgBase {
|
||||||
public final class AreaNPtg extends AreaPtg
|
|
||||||
{
|
|
||||||
public final static short sid = 0x2D;
|
public final static short sid = 0x2D;
|
||||||
|
|
||||||
protected AreaNPtg() {
|
public AreaNPtg(RecordInputStream in) {
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaNPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
super(in);
|
super(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAreaPtgName() {
|
protected byte getSid() {
|
||||||
return "AreaNPtg";
|
return sid;
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies a rectangular area of cells A1:A4 for instance.
|
|
||||||
* @author andy
|
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
|
||||||
*/
|
|
||||||
public final class AreaNVPtg extends AreaPtg {
|
|
||||||
public final static short sid = 0x4D;
|
|
||||||
|
|
||||||
protected AreaNVPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaNVPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
super(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAreaPtgName() {
|
|
||||||
return "AreaNVPtg";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
|
||||||
}
|
|
295
src/java/org/apache/poi/hssf/record/formula/AreaPtg.java
Normal file → Executable file
295
src/java/org/apache/poi/hssf/record/formula/AreaPtg.java
Normal file → Executable file
@ -17,302 +17,25 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
|
||||||
import org.apache.poi.util.BitField;
|
|
||||||
import org.apache.poi.util.BitFieldFactory;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.util.AreaReference;
|
|
||||||
import org.apache.poi.hssf.util.CellReference;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies a rectangular area of cells A1:A4 for instance.
|
* Specifies a rectangular area of cells A1:A4 for instance.
|
||||||
* @author andy
|
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
public class AreaPtg extends OperandPtg implements AreaI {
|
public final class AreaPtg extends AreaPtgBase {
|
||||||
/**
|
|
||||||
* TODO - (May-2008) fix subclasses of AreaPtg 'AreaN~' which are used in shared formulas.
|
|
||||||
* see similar comment in ReferencePtg
|
|
||||||
*/
|
|
||||||
protected final RuntimeException notImplemented() {
|
|
||||||
return new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
|
|
||||||
}
|
|
||||||
|
|
||||||
public final static short sid = 0x25;
|
public final static short sid = 0x25;
|
||||||
private final static int SIZE = 9;
|
|
||||||
/** zero based, unsigned 16 bit */
|
|
||||||
private int field_1_first_row;
|
|
||||||
/** zero based, unsigned 16 bit */
|
|
||||||
private int field_2_last_row;
|
|
||||||
/** zero based, unsigned 8 bit */
|
|
||||||
private int field_3_first_column;
|
|
||||||
/** zero based, unsigned 8 bit */
|
|
||||||
private int field_4_last_column;
|
|
||||||
|
|
||||||
private final static BitField rowRelative = BitFieldFactory.getInstance(0x8000);
|
public AreaPtg(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
|
||||||
private final static BitField colRelative = BitFieldFactory.getInstance(0x4000);
|
super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
|
||||||
private final static BitField columnMask = BitFieldFactory.getInstance(0x3FFF);
|
}
|
||||||
|
public AreaPtg(RecordInputStream in) {
|
||||||
protected AreaPtg() {
|
super(in);
|
||||||
//Required for clone methods
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AreaPtg(String arearef) {
|
public AreaPtg(String arearef) {
|
||||||
AreaReference ar = new AreaReference(arearef);
|
super(arearef);
|
||||||
CellReference firstCell = ar.getFirstCell();
|
|
||||||
CellReference lastCell = ar.getLastCell();
|
|
||||||
setFirstRow(firstCell.getRow());
|
|
||||||
setFirstColumn(firstCell.getCol());
|
|
||||||
setLastRow(lastCell.getRow());
|
|
||||||
setLastColumn(lastCell.getCol());
|
|
||||||
setFirstColRelative(!firstCell.isColAbsolute());
|
|
||||||
setLastColRelative(!lastCell.isColAbsolute());
|
|
||||||
setFirstRowRelative(!firstCell.isRowAbsolute());
|
|
||||||
setLastRowRelative(!lastCell.isRowAbsolute());
|
|
||||||
}
|
}
|
||||||
|
protected byte getSid() {
|
||||||
public AreaPtg(int firstRow, int lastRow, int firstColumn, int lastColumn,
|
return sid;
|
||||||
boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
|
|
||||||
|
|
||||||
checkColumnBounds(firstColumn);
|
|
||||||
checkColumnBounds(lastColumn);
|
|
||||||
checkRowBounds(firstRow);
|
|
||||||
checkRowBounds(lastRow);
|
|
||||||
setFirstRow(firstRow);
|
|
||||||
setLastRow(lastRow);
|
|
||||||
setFirstColumn(firstColumn);
|
|
||||||
setLastColumn(lastColumn);
|
|
||||||
setFirstRowRelative(firstRowRelative);
|
|
||||||
setLastRowRelative(lastRowRelative);
|
|
||||||
setFirstColRelative(firstColRelative);
|
|
||||||
setLastColRelative(lastColRelative);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void checkColumnBounds(int colIx) {
|
|
||||||
if((colIx & 0x0FF) != colIx) {
|
|
||||||
throw new IllegalArgumentException("colIx (" + colIx + ") is out of range");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void checkRowBounds(int rowIx) {
|
|
||||||
if((rowIx & 0x0FFFF) != rowIx) {
|
|
||||||
throw new IllegalArgumentException("rowIx (" + rowIx + ") is out of range");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
field_1_first_row = in.readUShort();
|
|
||||||
field_2_last_row = in.readUShort();
|
|
||||||
field_3_first_column = in.readUShort();
|
|
||||||
field_4_last_column = in.readUShort();
|
|
||||||
//System.out.println(toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAreaPtgName() {
|
|
||||||
return "AreaPtg";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
sb.append(getClass().getName());
|
|
||||||
sb.append(" [");
|
|
||||||
sb.append(AreaReference.formatAsString(this));
|
|
||||||
sb.append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset) {
|
|
||||||
array[offset] = (byte) (sid + ptgClass);
|
|
||||||
LittleEndian.putShort(array,offset+1,(short)field_1_first_row);
|
|
||||||
LittleEndian.putShort(array,offset+3,(short)field_2_last_row);
|
|
||||||
LittleEndian.putShort(array,offset+5,(short)field_3_first_column);
|
|
||||||
LittleEndian.putShort(array,offset+7,(short)field_4_last_column);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the first row in the area
|
|
||||||
*/
|
|
||||||
public int getFirstRow()
|
|
||||||
{
|
|
||||||
return field_1_first_row;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* sets the first row
|
|
||||||
* @param rowIx number (0-based)
|
|
||||||
*/
|
|
||||||
public void setFirstRow(int rowIx) {
|
|
||||||
checkRowBounds(rowIx);
|
|
||||||
field_1_first_row = rowIx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return last row in the range (x2 in x1,y1-x2,y2)
|
|
||||||
*/
|
|
||||||
public int getLastRow()
|
|
||||||
{
|
|
||||||
return field_2_last_row;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param rowIx last row number in the area
|
|
||||||
*/
|
|
||||||
public void setLastRow(int rowIx) {
|
|
||||||
checkRowBounds(rowIx);
|
|
||||||
field_2_last_row = rowIx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the first column number in the area.
|
|
||||||
*/
|
|
||||||
public int getFirstColumn()
|
|
||||||
{
|
|
||||||
return columnMask.getValue(field_3_first_column);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the first column number + the options bit settings unstripped
|
|
||||||
*/
|
|
||||||
public short getFirstColumnRaw()
|
|
||||||
{
|
|
||||||
return (short) field_3_first_column; // TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return whether or not the first row is a relative reference or not.
|
|
||||||
*/
|
|
||||||
public boolean isFirstRowRelative()
|
|
||||||
{
|
|
||||||
return rowRelative.isSet(field_3_first_column);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* sets the first row to relative or not
|
|
||||||
* @param rel is relative or not.
|
|
||||||
*/
|
|
||||||
public void setFirstRowRelative(boolean rel) {
|
|
||||||
field_3_first_column=rowRelative.setBoolean(field_3_first_column,rel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return isrelative first column to relative or not
|
|
||||||
*/
|
|
||||||
public boolean isFirstColRelative()
|
|
||||||
{
|
|
||||||
return colRelative.isSet(field_3_first_column);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set whether the first column is relative
|
|
||||||
*/
|
|
||||||
public void setFirstColRelative(boolean rel) {
|
|
||||||
field_3_first_column=colRelative.setBoolean(field_3_first_column,rel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the first column in the area
|
|
||||||
*/
|
|
||||||
public void setFirstColumn(int colIx) {
|
|
||||||
checkColumnBounds(colIx);
|
|
||||||
field_3_first_column=columnMask.setValue(field_3_first_column, colIx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the first column irespective of the bitmasks
|
|
||||||
*/
|
|
||||||
public void setFirstColumnRaw(int column)
|
|
||||||
{
|
|
||||||
field_3_first_column = column;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return lastcolumn in the area
|
|
||||||
*/
|
|
||||||
public int getLastColumn()
|
|
||||||
{
|
|
||||||
return columnMask.getValue(field_4_last_column);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return last column and bitmask (the raw field)
|
|
||||||
*/
|
|
||||||
public short getLastColumnRaw()
|
|
||||||
{
|
|
||||||
return (short) field_4_last_column;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return last row relative or not
|
|
||||||
*/
|
|
||||||
public boolean isLastRowRelative()
|
|
||||||
{
|
|
||||||
return rowRelative.isSet(field_4_last_column);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set whether the last row is relative or not
|
|
||||||
* @param rel <code>true</code> if the last row relative, else
|
|
||||||
* <code>false</code>
|
|
||||||
*/
|
|
||||||
public void setLastRowRelative(boolean rel) {
|
|
||||||
field_4_last_column=rowRelative.setBoolean(field_4_last_column,rel);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return lastcol relative or not
|
|
||||||
*/
|
|
||||||
public boolean isLastColRelative()
|
|
||||||
{
|
|
||||||
return colRelative.isSet(field_4_last_column);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set whether the last column should be relative or not
|
|
||||||
*/
|
|
||||||
public void setLastColRelative(boolean rel) {
|
|
||||||
field_4_last_column=colRelative.setBoolean(field_4_last_column,rel);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the last column in the area
|
|
||||||
*/
|
|
||||||
public void setLastColumn(int colIx) {
|
|
||||||
checkColumnBounds(colIx);
|
|
||||||
field_4_last_column=columnMask.setValue(field_4_last_column, colIx);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the last column irrespective of the bitmasks
|
|
||||||
*/
|
|
||||||
public void setLastColumnRaw(short column)
|
|
||||||
{
|
|
||||||
field_4_last_column = column;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book) {
|
|
||||||
return AreaReference.formatAsString(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getDefaultOperandClass() {
|
|
||||||
return Ptg.CLASS_REF;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
AreaPtg ptg = new AreaPtg();
|
|
||||||
ptg.field_1_first_row = field_1_first_row;
|
|
||||||
ptg.field_2_last_row = field_2_last_row;
|
|
||||||
ptg.field_3_first_column = field_3_first_column;
|
|
||||||
ptg.field_4_last_column = field_4_last_column;
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
286
src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java
Normal file
286
src/java/org/apache/poi/hssf/record/formula/AreaPtgBase.java
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
import org.apache.poi.util.BitField;
|
||||||
|
import org.apache.poi.util.BitFieldFactory;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.util.AreaReference;
|
||||||
|
import org.apache.poi.hssf.util.CellReference;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies a rectangular area of cells A1:A4 for instance.
|
||||||
|
* @author andy
|
||||||
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
|
*/
|
||||||
|
public abstract class AreaPtgBase extends OperandPtg implements AreaI {
|
||||||
|
/**
|
||||||
|
* TODO - (May-2008) fix subclasses of AreaPtg 'AreaN~' which are used in shared formulas.
|
||||||
|
* see similar comment in ReferencePtg
|
||||||
|
*/
|
||||||
|
protected final RuntimeException notImplemented() {
|
||||||
|
return new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static short sid = 0x25;
|
||||||
|
private final static int SIZE = 9;
|
||||||
|
/** zero based, unsigned 16 bit */
|
||||||
|
private int field_1_first_row;
|
||||||
|
/** zero based, unsigned 16 bit */
|
||||||
|
private int field_2_last_row;
|
||||||
|
/** zero based, unsigned 8 bit */
|
||||||
|
private int field_3_first_column;
|
||||||
|
/** zero based, unsigned 8 bit */
|
||||||
|
private int field_4_last_column;
|
||||||
|
|
||||||
|
private final static BitField rowRelative = BitFieldFactory.getInstance(0x8000);
|
||||||
|
private final static BitField colRelative = BitFieldFactory.getInstance(0x4000);
|
||||||
|
private final static BitField columnMask = BitFieldFactory.getInstance(0x3FFF);
|
||||||
|
|
||||||
|
protected AreaPtgBase(String arearef) {
|
||||||
|
AreaReference ar = new AreaReference(arearef);
|
||||||
|
CellReference firstCell = ar.getFirstCell();
|
||||||
|
CellReference lastCell = ar.getLastCell();
|
||||||
|
setFirstRow(firstCell.getRow());
|
||||||
|
setFirstColumn(firstCell.getCol());
|
||||||
|
setLastRow(lastCell.getRow());
|
||||||
|
setLastColumn(lastCell.getCol());
|
||||||
|
setFirstColRelative(!firstCell.isColAbsolute());
|
||||||
|
setLastColRelative(!lastCell.isColAbsolute());
|
||||||
|
setFirstRowRelative(!firstCell.isRowAbsolute());
|
||||||
|
setLastRowRelative(!lastCell.isRowAbsolute());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AreaPtgBase(int firstRow, int lastRow, int firstColumn, int lastColumn,
|
||||||
|
boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
|
||||||
|
|
||||||
|
checkColumnBounds(firstColumn);
|
||||||
|
checkColumnBounds(lastColumn);
|
||||||
|
checkRowBounds(firstRow);
|
||||||
|
checkRowBounds(lastRow);
|
||||||
|
setFirstRow(firstRow);
|
||||||
|
setLastRow(lastRow);
|
||||||
|
setFirstColumn(firstColumn);
|
||||||
|
setLastColumn(lastColumn);
|
||||||
|
setFirstRowRelative(firstRowRelative);
|
||||||
|
setLastRowRelative(lastRowRelative);
|
||||||
|
setFirstColRelative(firstColRelative);
|
||||||
|
setLastColRelative(lastColRelative);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkColumnBounds(int colIx) {
|
||||||
|
if((colIx & 0x0FF) != colIx) {
|
||||||
|
throw new IllegalArgumentException("colIx (" + colIx + ") is out of range");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static void checkRowBounds(int rowIx) {
|
||||||
|
if((rowIx & 0x0FFFF) != rowIx) {
|
||||||
|
throw new IllegalArgumentException("rowIx (" + rowIx + ") is out of range");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AreaPtgBase(RecordInputStream in)
|
||||||
|
{
|
||||||
|
field_1_first_row = in.readUShort();
|
||||||
|
field_2_last_row = in.readUShort();
|
||||||
|
field_3_first_column = in.readUShort();
|
||||||
|
field_4_last_column = in.readUShort();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String toString() {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append(getClass().getName());
|
||||||
|
sb.append(" [");
|
||||||
|
sb.append(AreaReference.formatAsString(this));
|
||||||
|
sb.append("]");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
protected abstract byte getSid();
|
||||||
|
|
||||||
|
public final void writeBytes(byte [] array, int offset) {
|
||||||
|
array[offset] = (byte) (getSid() + getPtgClass());
|
||||||
|
LittleEndian.putShort(array,offset+1,(short)field_1_first_row);
|
||||||
|
LittleEndian.putShort(array,offset+3,(short)field_2_last_row);
|
||||||
|
LittleEndian.putShort(array,offset+5,(short)field_3_first_column);
|
||||||
|
LittleEndian.putShort(array,offset+7,(short)field_4_last_column);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final int getSize() {
|
||||||
|
return SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the first row in the area
|
||||||
|
*/
|
||||||
|
public final int getFirstRow() {
|
||||||
|
return field_1_first_row;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the first row
|
||||||
|
* @param rowIx number (0-based)
|
||||||
|
*/
|
||||||
|
public final void setFirstRow(int rowIx) {
|
||||||
|
checkRowBounds(rowIx);
|
||||||
|
field_1_first_row = rowIx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return last row in the range (x2 in x1,y1-x2,y2)
|
||||||
|
*/
|
||||||
|
public final int getLastRow() {
|
||||||
|
return field_2_last_row;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param rowIx last row number in the area
|
||||||
|
*/
|
||||||
|
public final void setLastRow(int rowIx) {
|
||||||
|
checkRowBounds(rowIx);
|
||||||
|
field_2_last_row = rowIx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the first column number in the area.
|
||||||
|
*/
|
||||||
|
public final int getFirstColumn() {
|
||||||
|
return columnMask.getValue(field_3_first_column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the first column number + the options bit settings unstripped
|
||||||
|
*/
|
||||||
|
public final short getFirstColumnRaw() {
|
||||||
|
return (short) field_3_first_column; // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether or not the first row is a relative reference or not.
|
||||||
|
*/
|
||||||
|
public final boolean isFirstRowRelative() {
|
||||||
|
return rowRelative.isSet(field_3_first_column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the first row to relative or not
|
||||||
|
* @param rel is relative or not.
|
||||||
|
*/
|
||||||
|
public final void setFirstRowRelative(boolean rel) {
|
||||||
|
field_3_first_column=rowRelative.setBoolean(field_3_first_column,rel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return isrelative first column to relative or not
|
||||||
|
*/
|
||||||
|
public final boolean isFirstColRelative() {
|
||||||
|
return colRelative.isSet(field_3_first_column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set whether the first column is relative
|
||||||
|
*/
|
||||||
|
public final void setFirstColRelative(boolean rel) {
|
||||||
|
field_3_first_column=colRelative.setBoolean(field_3_first_column,rel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the first column in the area
|
||||||
|
*/
|
||||||
|
public final void setFirstColumn(int colIx) {
|
||||||
|
checkColumnBounds(colIx);
|
||||||
|
field_3_first_column=columnMask.setValue(field_3_first_column, colIx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the first column irrespective of the bitmasks
|
||||||
|
*/
|
||||||
|
public final void setFirstColumnRaw(int column) {
|
||||||
|
field_3_first_column = column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return lastcolumn in the area
|
||||||
|
*/
|
||||||
|
public final int getLastColumn() {
|
||||||
|
return columnMask.getValue(field_4_last_column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return last column and bitmask (the raw field)
|
||||||
|
*/
|
||||||
|
public final short getLastColumnRaw() {
|
||||||
|
return (short) field_4_last_column;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return last row relative or not
|
||||||
|
*/
|
||||||
|
public final boolean isLastRowRelative() {
|
||||||
|
return rowRelative.isSet(field_4_last_column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set whether the last row is relative or not
|
||||||
|
* @param rel <code>true</code> if the last row relative, else
|
||||||
|
* <code>false</code>
|
||||||
|
*/
|
||||||
|
public final void setLastRowRelative(boolean rel) {
|
||||||
|
field_4_last_column=rowRelative.setBoolean(field_4_last_column,rel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return lastcol relative or not
|
||||||
|
*/
|
||||||
|
public final boolean isLastColRelative() {
|
||||||
|
return colRelative.isSet(field_4_last_column);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set whether the last column should be relative or not
|
||||||
|
*/
|
||||||
|
public final void setLastColRelative(boolean rel) {
|
||||||
|
field_4_last_column=colRelative.setBoolean(field_4_last_column,rel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the last column in the area
|
||||||
|
*/
|
||||||
|
public final void setLastColumn(int colIx) {
|
||||||
|
checkColumnBounds(colIx);
|
||||||
|
field_4_last_column=columnMask.setValue(field_4_last_column, colIx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the last column irrespective of the bitmasks
|
||||||
|
*/
|
||||||
|
public final void setLastColumnRaw(short column) {
|
||||||
|
field_4_last_column = column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toFormulaString(HSSFWorkbook book) {
|
||||||
|
return AreaReference.formatAsString(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getDefaultOperandClass() {
|
||||||
|
return Ptg.CLASS_REF;
|
||||||
|
}
|
||||||
|
}
|
@ -1,71 +0,0 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* AreaPtg.java
|
|
||||||
*
|
|
||||||
* Created on November 17, 2001, 9:30 PM
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
|
||||||
import org.apache.poi.util.BitField;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
import org.apache.poi.hssf.util.AreaReference;
|
|
||||||
import org.apache.poi.hssf.util.CellReference;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies a rectangular area of cells A1:A4 for instance.
|
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
|
||||||
*/
|
|
||||||
|
|
||||||
public final class AreaVPtg
|
|
||||||
extends AreaPtg
|
|
||||||
{
|
|
||||||
public final static short sid = 0x45;
|
|
||||||
|
|
||||||
protected AreaVPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public AreaVPtg(int firstRow, int lastRow, int firstColumn, int lastColumn, boolean firstRowRelative, boolean lastRowRelative, boolean firstColRelative, boolean lastColRelative) {
|
|
||||||
super(firstRow, lastRow, firstColumn, lastColumn, firstRowRelative, lastRowRelative, firstColRelative, lastColRelative);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public AreaVPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
super(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAreaPtgName() {
|
|
||||||
return "AreaVPtg";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
AreaVPtg ptg = new AreaVPtg();
|
|
||||||
ptg.setFirstRow(getFirstRow());
|
|
||||||
ptg.setLastRow(getLastRow());
|
|
||||||
ptg.setFirstColumnRaw(getFirstColumnRaw());
|
|
||||||
ptg.setLastColumnRaw(getLastColumnRaw());
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
|
@ -35,29 +35,28 @@ import org.apache.poi.util.LittleEndian;
|
|||||||
*
|
*
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
public class ArrayPtg extends Ptg {
|
public final class ArrayPtg extends Ptg {
|
||||||
public static final byte sid = 0x20;
|
public static final byte sid = 0x20;
|
||||||
|
|
||||||
private static final int RESERVED_FIELD_LEN = 7;
|
private static final int RESERVED_FIELD_LEN = 7;
|
||||||
// TODO - fix up field visibility and subclasses
|
// TODO - fix up field visibility and subclasses
|
||||||
protected byte[] field_1_reserved;
|
private byte[] field_1_reserved;
|
||||||
|
|
||||||
// data from these fields comes after the Ptg data of all tokens in current formula
|
// data from these fields comes after the Ptg data of all tokens in current formula
|
||||||
protected short token_1_columns;
|
private short token_1_columns;
|
||||||
protected short token_2_rows;
|
private short token_2_rows;
|
||||||
protected Object[] token_3_arrayValues;
|
private Object[] token_3_arrayValues;
|
||||||
|
|
||||||
protected ArrayPtg() {
|
public ArrayPtg(RecordInputStream in) {
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
field_1_reserved = new byte[RESERVED_FIELD_LEN];
|
field_1_reserved = new byte[RESERVED_FIELD_LEN];
|
||||||
// TODO - add readFully method to RecordInputStream
|
// TODO - add readFully method to RecordInputStream
|
||||||
for(int i=0; i< RESERVED_FIELD_LEN; i++) {
|
for(int i=0; i< RESERVED_FIELD_LEN; i++) {
|
||||||
field_1_reserved[i] = in.readByte();
|
field_1_reserved[i] = in.readByte();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public Object[] getTokenArrayValues() {
|
||||||
|
return (Object[]) token_3_arrayValues.clone();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isBaseToken() {
|
public boolean isBaseToken() {
|
||||||
return false;
|
return false;
|
||||||
@ -117,7 +116,7 @@ public class ArrayPtg extends Ptg {
|
|||||||
|
|
||||||
public void writeBytes(byte[] data, int offset) {
|
public void writeBytes(byte[] data, int offset) {
|
||||||
|
|
||||||
LittleEndian.putByte(data, offset + 0, sid + ptgClass);
|
LittleEndian.putByte(data, offset + 0, sid + getPtgClass());
|
||||||
System.arraycopy(field_1_reserved, 0, data, offset+1, RESERVED_FIELD_LEN);
|
System.arraycopy(field_1_reserved, 0, data, offset+1, RESERVED_FIELD_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,13 +189,9 @@ public class ArrayPtg extends Ptg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
ArrayPtg ptg = new ArrayPtg();
|
ArrayPtg ptg = (ArrayPtg) super.clone();
|
||||||
ptg.field_1_reserved = (byte[]) field_1_reserved.clone();
|
ptg.field_1_reserved = (byte[]) field_1_reserved.clone();
|
||||||
|
|
||||||
ptg.token_1_columns = token_1_columns;
|
|
||||||
ptg.token_2_rows = token_2_rows;
|
|
||||||
ptg.token_3_arrayValues = (Object[]) token_3_arrayValues.clone();
|
ptg.token_3_arrayValues = (Object[]) token_3_arrayValues.clone();
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
return ptg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ArrayPtgA - handles arrays
|
|
||||||
*
|
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
|
||||||
*/
|
|
||||||
public final class ArrayPtgA extends ArrayPtg {
|
|
||||||
public final static byte sid = 0x60;
|
|
||||||
|
|
||||||
private ArrayPtgA() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayPtgA(RecordInputStream in) {
|
|
||||||
super(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
ArrayPtgA ptg = new ArrayPtgA();
|
|
||||||
ptg.field_1_reserved = (byte[]) field_1_reserved.clone();
|
|
||||||
|
|
||||||
ptg.token_1_columns = token_1_columns;
|
|
||||||
ptg.token_2_rows = token_2_rows;
|
|
||||||
ptg.token_3_arrayValues = (Object[]) token_3_arrayValues.clone();
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ArrayPtg - handles arrays
|
|
||||||
*
|
|
||||||
* The ArrayPtg is a little weird, the size of the Ptg when parsing initially only
|
|
||||||
* includes the Ptg sid and the reserved bytes. The next Ptg in the expression then follows.
|
|
||||||
* It is only after the "size" of all the Ptgs is met, that the ArrayPtg data is actually
|
|
||||||
* held after this. So Ptg.createParsedExpression keeps track of the number of
|
|
||||||
* ArrayPtg elements and need to parse the data upto the FORMULA record size.
|
|
||||||
*
|
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
|
||||||
*/
|
|
||||||
public final class ArrayPtgV extends ArrayPtg {
|
|
||||||
public final static byte sid = 0x40;
|
|
||||||
|
|
||||||
private ArrayPtgV() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayPtgV(RecordInputStream in) {
|
|
||||||
super(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
ArrayPtgV ptg = new ArrayPtgV();
|
|
||||||
ptg.field_1_reserved = (byte[]) field_1_reserved.clone();
|
|
||||||
|
|
||||||
ptg.token_1_columns = token_1_columns;
|
|
||||||
ptg.token_2_rows = token_2_rows;
|
|
||||||
ptg.token_3_arrayValues = (Object[]) token_3_arrayValues.clone();
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
|
@ -30,11 +30,7 @@ import org.apache.poi.hssf.record.RecordInputStream;
|
|||||||
public final class BoolPtg extends ScalarConstantPtg {
|
public final class BoolPtg extends ScalarConstantPtg {
|
||||||
public final static int SIZE = 2;
|
public final static int SIZE = 2;
|
||||||
public final static byte sid = 0x1d;
|
public final static byte sid = 0x1d;
|
||||||
private boolean field_1_value;
|
private final boolean field_1_value;
|
||||||
|
|
||||||
private BoolPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public BoolPtg(RecordInputStream in)
|
public BoolPtg(RecordInputStream in)
|
||||||
{
|
{
|
||||||
@ -46,11 +42,6 @@ public final class BoolPtg extends ScalarConstantPtg {
|
|||||||
field_1_value = (formulaToken.equals("TRUE"));
|
field_1_value = (formulaToken.equals("TRUE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(boolean value)
|
|
||||||
{
|
|
||||||
field_1_value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getValue()
|
public boolean getValue()
|
||||||
{
|
{
|
||||||
return field_1_value;
|
return field_1_value;
|
||||||
@ -71,10 +62,4 @@ public final class BoolPtg extends ScalarConstantPtg {
|
|||||||
{
|
{
|
||||||
return field_1_value ? "TRUE" : "FALSE";
|
return field_1_value ? "TRUE" : "FALSE";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
BoolPtg ptg = new BoolPtg();
|
|
||||||
ptg.field_1_value = field_1_value;
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,55 +17,30 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author andy
|
* @author andy
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
public final class ConcatPtg extends ValueOperatorPtg {
|
public final class ConcatPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x08;
|
public final static byte sid = 0x08;
|
||||||
|
|
||||||
private final static String CONCAT = "&";
|
private final static String CONCAT = "&";
|
||||||
|
|
||||||
public ConcatPtg(RecordInputStream in)
|
public static final ValueOperatorPtg instance = new ConcatPtg();
|
||||||
{
|
|
||||||
// No contents
|
private ConcatPtg() {
|
||||||
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcatPtg() {
|
protected byte getSid() {
|
||||||
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public int getNumberOfOperands() {
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return CONCAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
@ -74,9 +49,4 @@ public final class ConcatPtg extends ValueOperatorPtg {
|
|||||||
buffer.append(operands[ 1 ]);
|
buffer.append(operands[ 1 ]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new ConcatPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,66 +17,34 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This PTG implements the standard binomial divide "/"
|
* This PTG implements the standard binomial divide "/"
|
||||||
* @author Andrew C. Oliver acoliver at apache dot org
|
* @author Andrew C. Oliver acoliver at apache dot org
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
public final class DividePtg extends ValueOperatorPtg {
|
public final class DividePtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x06;
|
public final static byte sid = 0x06;
|
||||||
|
|
||||||
/** Creates new AddPtg */
|
public static final ValueOperatorPtg instance = new DividePtg();
|
||||||
|
|
||||||
public DividePtg()
|
private DividePtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public DividePtg(RecordInputStream in)
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public int getNumberOfOperands() {
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
buffer.append(operands[ 0 ]);
|
buffer.append(operands[ 0 ]);
|
||||||
buffer.append(toFormulaString((HSSFWorkbook)null));
|
buffer.append("/");
|
||||||
buffer.append(operands[ 1 ]);
|
buffer.append(operands[ 1 ]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
DividePtg ptg = new DividePtg();
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,67 +17,34 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author andy
|
* @author andy
|
||||||
*/
|
*/
|
||||||
public final class EqualPtg extends ValueOperatorPtg {
|
public final class EqualPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x0b;
|
public final static byte sid = 0x0b;
|
||||||
|
|
||||||
/** Creates new AddPtg */
|
public static final ValueOperatorPtg instance = new EqualPtg();
|
||||||
|
|
||||||
public EqualPtg()
|
private EqualPtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public EqualPtg(RecordInputStream in)
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public int getNumberOfOperands() {
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return "=";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
|
|
||||||
buffer.append(operands[ 0 ]);
|
buffer.append(operands[ 0 ]);
|
||||||
buffer.append(toFormulaString((HSSFWorkbook)null));
|
buffer.append("=");
|
||||||
buffer.append(operands[ 1 ]);
|
buffer.append(operands[ 1 ]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new EqualPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public final class ErrPtg extends ScalarConstantPtg {
|
|||||||
|
|
||||||
public static final short sid = 0x1c;
|
public static final short sid = 0x1c;
|
||||||
private static final int SIZE = 2;
|
private static final int SIZE = 2;
|
||||||
private int field_1_error_code;
|
private final int field_1_error_code;
|
||||||
|
|
||||||
/** Creates new ErrPtg */
|
/** Creates new ErrPtg */
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ public final class ErrPtg extends ScalarConstantPtg {
|
|||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public void writeBytes(byte [] array, int offset)
|
||||||
{
|
{
|
||||||
array[offset] = (byte) (sid + ptgClass);
|
array[offset] = (byte) (sid + getPtgClass());
|
||||||
array[offset + 1] = (byte)field_1_error_code;
|
array[offset + 1] = (byte)field_1_error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,10 +76,6 @@ public final class ErrPtg extends ScalarConstantPtg {
|
|||||||
return SIZE;
|
return SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new ErrPtg(field_1_error_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getErrorCode() {
|
public int getErrorCode() {
|
||||||
return field_1_error_code;
|
return field_1_error_code;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -30,20 +29,11 @@ import org.apache.poi.util.LittleEndian;
|
|||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
* @author dmui (save existing implementation)
|
* @author dmui (save existing implementation)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class ExpPtg extends ControlPtg {
|
public final class ExpPtg extends ControlPtg {
|
||||||
private final static int SIZE = 5;
|
private final static int SIZE = 5;
|
||||||
public final static short sid = 0x1;
|
public final static short sid = 0x1;
|
||||||
private short field_1_first_row;
|
private final short field_1_first_row;
|
||||||
private short field_2_first_col;
|
private final short field_2_first_col;
|
||||||
|
|
||||||
/** Creates new ExpPtg */
|
|
||||||
|
|
||||||
public ExpPtg()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates new ExpPtg */
|
|
||||||
|
|
||||||
public ExpPtg(RecordInputStream in)
|
public ExpPtg(RecordInputStream in)
|
||||||
{
|
{
|
||||||
@ -83,12 +73,4 @@ public final class ExpPtg extends ControlPtg {
|
|||||||
buffer.append("col = ").append(getColumn()).append("\n");
|
buffer.append("col = ").append(getColumn()).append("\n");
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
ExpPtg result = new ExpPtg();
|
|
||||||
result.field_1_first_row = field_1_first_row;
|
|
||||||
result.field_2_first_col = field_2_first_col;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public final class FuncPtg extends AbstractFunctionPtg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte[] array, int offset) {
|
public void writeBytes(byte[] array, int offset) {
|
||||||
array[offset+0]= (byte) (sid + ptgClass);
|
array[offset+0]= (byte) (sid + getPtgClass());
|
||||||
LittleEndian.putShort(array,offset+1,field_2_fnc_index);
|
LittleEndian.putShort(array,offset+1,field_2_fnc_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,12 +64,6 @@ public final class FuncPtg extends AbstractFunctionPtg {
|
|||||||
return numParams;
|
return numParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
FuncPtg ptg = new FuncPtg(field_2_fnc_index);
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return SIZE;
|
return SIZE;
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,6 @@ public final class FuncVarPtg extends AbstractFunctionPtg{
|
|||||||
public final static byte sid = 0x22;
|
public final static byte sid = 0x22;
|
||||||
private final static int SIZE = 4;
|
private final static int SIZE = 4;
|
||||||
|
|
||||||
private FuncVarPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Creates new function pointer from a byte array
|
/**Creates new function pointer from a byte array
|
||||||
* usually called while reading an excel file.
|
* usually called while reading an excel file.
|
||||||
*/
|
*/
|
||||||
@ -69,7 +65,7 @@ public final class FuncVarPtg extends AbstractFunctionPtg{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte[] array, int offset) {
|
public void writeBytes(byte[] array, int offset) {
|
||||||
array[offset+0]=(byte) (sid + ptgClass);
|
array[offset+0]=(byte) (sid + getPtgClass());
|
||||||
array[offset+1]=field_1_num_args;
|
array[offset+1]=field_1_num_args;
|
||||||
LittleEndian.putShort(array,offset+2,field_2_fnc_index);
|
LittleEndian.putShort(array,offset+2,field_2_fnc_index);
|
||||||
}
|
}
|
||||||
@ -78,14 +74,6 @@ public final class FuncVarPtg extends AbstractFunctionPtg{
|
|||||||
return field_1_num_args;
|
return field_1_num_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
FuncVarPtg ptg = new FuncVarPtg();
|
|
||||||
ptg.field_1_num_args = field_1_num_args;
|
|
||||||
ptg.field_2_fnc_index = field_2_fnc_index;
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return SIZE;
|
return SIZE;
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PTG class to implement greater or equal to
|
* PTG class to implement greater or equal to
|
||||||
@ -29,56 +27,28 @@ public final class GreaterEqualPtg extends ValueOperatorPtg {
|
|||||||
public final static int SIZE = 1;
|
public final static int SIZE = 1;
|
||||||
public final static byte sid = 0x0c;
|
public final static byte sid = 0x0c;
|
||||||
|
|
||||||
/** Creates new GreaterEqualPtg */
|
public static final ValueOperatorPtg instance = new GreaterEqualPtg();
|
||||||
|
|
||||||
public GreaterEqualPtg()
|
private GreaterEqualPtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public GreaterEqualPtg(RecordInputStream in)
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public int getNumberOfOperands() {
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return ">=";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
buffer.append(operands[ 0 ]);
|
buffer.append(operands[ 0 ]);
|
||||||
|
|
||||||
buffer.append(toFormulaString((HSSFWorkbook)null));
|
buffer.append(">=");
|
||||||
buffer.append(operands[ 1 ]);
|
buffer.append(operands[ 1 ]);
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new GreaterEqualPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,81 +17,33 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Greater than operator PTG ">"
|
* Greater than operator PTG ">"
|
||||||
* @author Cameron Riley (criley at ekmail.com)
|
* @author Cameron Riley (criley at ekmail.com)
|
||||||
*/
|
*/
|
||||||
public final class GreaterThanPtg extends ValueOperatorPtg {
|
public final class GreaterThanPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x0D;
|
public final static byte sid = 0x0D;
|
||||||
private final static String GREATERTHAN = ">";
|
private final static String GREATERTHAN = ">";
|
||||||
|
|
||||||
/**
|
public static final ValueOperatorPtg instance = new GreaterThanPtg();
|
||||||
* Constructor. Creates new GreaterThanPtg
|
|
||||||
*/
|
private GreaterThanPtg() {
|
||||||
public GreaterThanPtg()
|
// enforce singleton
|
||||||
{
|
|
||||||
//deliberately empty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected byte getSid() {
|
||||||
* Constructor. Create a new GreaterThanPtg.
|
return sid;
|
||||||
* @param in the RecordInputstream to read the record from
|
|
||||||
*/
|
|
||||||
public GreaterThanPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
//deliberately empty
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write the sid to an array
|
|
||||||
* @param array the array of bytes to write the sid to
|
|
||||||
* @param offset the offset to add the sid to
|
|
||||||
*/
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the size of the sid
|
|
||||||
* @return int the size of the sid in terms of byte additions to an array
|
|
||||||
*/
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the type of PTG for Greater Than
|
|
||||||
* @return int the identifier for the type
|
|
||||||
*/
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of operands for the Less than operator
|
* Get the number of operands for the Less than operator
|
||||||
* @return int the number of operands
|
* @return int the number of operands
|
||||||
*/
|
*/
|
||||||
public int getNumberOfOperands()
|
public int getNumberOfOperands() {
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of method from Ptg
|
|
||||||
* @param book the Sheet References
|
|
||||||
*/
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return this.GREATERTHAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of method from OperationsPtg
|
* Implementation of method from OperationsPtg
|
||||||
* @param operands a String array of operands
|
* @param operands a String array of operands
|
||||||
@ -102,17 +54,8 @@ public final class GreaterThanPtg extends ValueOperatorPtg {
|
|||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
buffer.append(operands[ 0 ]);
|
buffer.append(operands[ 0 ]);
|
||||||
buffer.append(this.GREATERTHAN);
|
buffer.append(GREATERTHAN);
|
||||||
buffer.append(operands[ 1 ]);
|
buffer.append(operands[ 1 ]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of clone method from Object
|
|
||||||
* @return Object a clone of this class as an Object
|
|
||||||
*/
|
|
||||||
public Object clone()
|
|
||||||
{
|
|
||||||
return new GreaterThanPtg();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,12 @@ public final class IntPtg extends ScalarConstantPtg {
|
|||||||
|
|
||||||
public final static int SIZE = 3;
|
public final static int SIZE = 3;
|
||||||
public final static byte sid = 0x1e;
|
public final static byte sid = 0x1e;
|
||||||
private int field_1_value;
|
private final int field_1_value;
|
||||||
|
|
||||||
public IntPtg(RecordInputStream in) {
|
public IntPtg(RecordInputStream in) {
|
||||||
this(in.readUShort());
|
this(in.readUShort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IntPtg(int value) {
|
public IntPtg(int value) {
|
||||||
if(!isInRange(value)) {
|
if(!isInRange(value)) {
|
||||||
throw new IllegalArgumentException("value is out of range: " + value);
|
throw new IllegalArgumentException("value is out of range: " + value);
|
||||||
@ -61,7 +60,6 @@ public final class IntPtg extends ScalarConstantPtg {
|
|||||||
return field_1_value;
|
return field_1_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public void writeBytes(byte [] array, int offset)
|
||||||
{
|
{
|
||||||
array[ offset + 0 ] = sid;
|
array[ offset + 0 ] = sid;
|
||||||
@ -76,9 +74,6 @@ public final class IntPtg extends ScalarConstantPtg {
|
|||||||
return String.valueOf(getValue());
|
return String.valueOf(getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new IntPtg(field_1_value);
|
|
||||||
}
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer(64);
|
StringBuffer sb = new StringBuffer(64);
|
||||||
sb.append(getClass().getName()).append(" [");
|
sb.append(getClass().getName()).append(" [");
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Daniel Noll (daniel at nuix dot com dot au)
|
* @author Daniel Noll (daniel at nuix dot com dot au)
|
||||||
@ -26,14 +25,10 @@ import org.apache.poi.hssf.record.RecordInputStream;
|
|||||||
public final class IntersectionPtg extends OperationPtg {
|
public final class IntersectionPtg extends OperationPtg {
|
||||||
public final static byte sid = 0x0f;
|
public final static byte sid = 0x0f;
|
||||||
|
|
||||||
|
public static final OperationPtg instance = new IntersectionPtg();
|
||||||
|
|
||||||
public IntersectionPtg()
|
private IntersectionPtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
|
||||||
|
|
||||||
public IntersectionPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isBaseToken() {
|
public final boolean isBaseToken() {
|
||||||
@ -50,16 +45,6 @@ public final class IntersectionPtg extends OperationPtg {
|
|||||||
array[ offset + 0 ] = sid;
|
array[ offset + 0 ] = sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone()
|
|
||||||
{
|
|
||||||
return new IntersectionPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implementation of method from Ptg */
|
/** Implementation of method from Ptg */
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
public String toFormulaString(HSSFWorkbook book)
|
||||||
{
|
{
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,58 +27,27 @@ import org.apache.poi.hssf.record.RecordInputStream;
|
|||||||
* @author fred at stsci dot edu
|
* @author fred at stsci dot edu
|
||||||
*/
|
*/
|
||||||
public final class LessEqualPtg extends ValueOperatorPtg {
|
public final class LessEqualPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x0a;
|
public final static byte sid = 0x0a;
|
||||||
|
|
||||||
/**
|
public static final ValueOperatorPtg instance = new LessEqualPtg();
|
||||||
* Creates new LessEqualPtg
|
|
||||||
*/
|
|
||||||
public LessEqualPtg()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
private LessEqualPtg() {
|
||||||
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public LessEqualPtg( RecordInputStream in )
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes( byte[] array, int offset )
|
public int getNumberOfOperands() {
|
||||||
{
|
|
||||||
array[offset + 0] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString( HSSFWorkbook book )
|
public String toFormulaString(String[] operands) {
|
||||||
{
|
|
||||||
return "<=";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString( String[] operands )
|
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append( operands[0] );
|
buffer.append( operands[0] );
|
||||||
buffer.append( toFormulaString( (HSSFWorkbook) null ) );
|
buffer.append("<=");
|
||||||
buffer.append( operands[1] );
|
buffer.append( operands[1] );
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone()
|
|
||||||
{
|
|
||||||
return new LessEqualPtg();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,6 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Less than operator PTG "<". The SID is taken from the
|
* Less than operator PTG "<". The SID is taken from the
|
||||||
* Openoffice.orgs Documentation of the Excel File Format,
|
* Openoffice.orgs Documentation of the Excel File Format,
|
||||||
@ -27,78 +24,30 @@ import org.apache.poi.hssf.record.RecordInputStream;
|
|||||||
* @author Cameron Riley (criley at ekmail.com)
|
* @author Cameron Riley (criley at ekmail.com)
|
||||||
*/
|
*/
|
||||||
public final class LessThanPtg extends ValueOperatorPtg {
|
public final class LessThanPtg extends ValueOperatorPtg {
|
||||||
/** the size of the Ptg */
|
|
||||||
public final static int SIZE = 1;
|
|
||||||
|
|
||||||
/** the sid for the less than operator as hex */
|
/** the sid for the less than operator as hex */
|
||||||
public final static byte sid = 0x09;
|
public final static byte sid = 0x09;
|
||||||
|
|
||||||
/** identifier for LESS THAN char */
|
/** identifier for LESS THAN char */
|
||||||
private final static String LESSTHAN = "<";
|
private final static String LESSTHAN = "<";
|
||||||
|
|
||||||
/**
|
public static final ValueOperatorPtg instance = new LessThanPtg();
|
||||||
* Constructor. Creates new LessThanPtg
|
|
||||||
*/
|
private LessThanPtg() {
|
||||||
public LessThanPtg()
|
// enforce singleton
|
||||||
{
|
|
||||||
//deliberately empty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected byte getSid() {
|
||||||
* Constructor. Create a new LessThanPtg.
|
return sid;
|
||||||
* @param in the RecordInputstream to read the record from
|
|
||||||
*/
|
|
||||||
public LessThanPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
//deliberately empty
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write the sid to an array
|
|
||||||
* @param array the array of bytes to write the sid to
|
|
||||||
* @param offset the offset to add the sid to
|
|
||||||
*/
|
|
||||||
public void writeBytes(byte[] array, int offset)
|
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the size of the sid
|
|
||||||
* @return int the size of the sid in terms of byte additions to an array
|
|
||||||
*/
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the type of PTG for Less Than
|
|
||||||
* @return int the identifier for the type
|
|
||||||
*/
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of operands for the Less than operator
|
* Get the number of operands for the Less than operator
|
||||||
* @return int the number of operands
|
* @return int the number of operands
|
||||||
*/
|
*/
|
||||||
public int getNumberOfOperands()
|
public int getNumberOfOperands() {
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of method from Ptg
|
|
||||||
* @param book the Sheet References
|
|
||||||
*/
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return this.LESSTHAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of method from OperationsPtg
|
* Implementation of method from OperationsPtg
|
||||||
* @param operands a String array of operands
|
* @param operands a String array of operands
|
||||||
@ -108,18 +57,8 @@ public final class LessThanPtg extends ValueOperatorPtg {
|
|||||||
{
|
{
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append(operands[ 0 ]);
|
buffer.append(operands[ 0 ]);
|
||||||
buffer.append(this.LESSTHAN);
|
buffer.append(LESSTHAN);
|
||||||
buffer.append(operands[ 1 ]);
|
buffer.append(operands[ 1 ]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of clone method from Object
|
|
||||||
* @return Object a clone of this class as an Object
|
|
||||||
*/
|
|
||||||
public Object clone()
|
|
||||||
{
|
|
||||||
return new LessThanPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public class MemAreaPtg extends OperandPtg {
|
|||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public void writeBytes(byte [] array, int offset)
|
||||||
{
|
{
|
||||||
array[offset] = (byte) (sid + ptgClass);
|
array[offset] = (byte) (sid + getPtgClass());
|
||||||
LittleEndian.putInt(array, offset + 1, field_1_reserved);
|
LittleEndian.putInt(array, offset + 1, field_1_reserved);
|
||||||
LittleEndian.putShort(array, offset + 5, field_2_subex_len);
|
LittleEndian.putShort(array, offset + 5, field_2_subex_len);
|
||||||
}
|
}
|
||||||
@ -79,12 +79,7 @@ public class MemAreaPtg extends OperandPtg {
|
|||||||
return ""; // TODO: Not sure how to format this. -- DN
|
return ""; // TODO: Not sure how to format this. -- DN
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
|
public byte getDefaultOperandClass() {
|
||||||
|
return Ptg.CLASS_VALUE;
|
||||||
public Object clone() {
|
|
||||||
MemAreaPtg ptg = new MemAreaPtg();
|
|
||||||
ptg.field_1_reserved = field_1_reserved;
|
|
||||||
ptg.field_2_subex_len = field_2_subex_len;
|
|
||||||
return ptg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,17 +15,10 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* MemErrPtg.java
|
|
||||||
*
|
|
||||||
* Created on November 21, 2001, 8:46 AM
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -35,9 +27,7 @@ import org.apache.poi.hssf.record.RecordInputStream;
|
|||||||
* @author Daniel Noll (daniel at nuix dot com dot au)
|
* @author Daniel Noll (daniel at nuix dot com dot au)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MemErrPtg
|
public final class MemErrPtg extends MemAreaPtg {
|
||||||
extends MemAreaPtg
|
|
||||||
{
|
|
||||||
public final static short sid = 0x27;
|
public final static short sid = 0x27;
|
||||||
|
|
||||||
/** Creates new MemErrPtg */
|
/** Creates new MemErrPtg */
|
||||||
@ -46,26 +36,17 @@ public class MemErrPtg
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemErrPtg(RecordInputStream in)
|
public MemErrPtg(RecordInputStream in) {
|
||||||
{
|
|
||||||
super(in);
|
super(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public void writeBytes(byte [] array, int offset) {
|
||||||
{
|
|
||||||
super.writeBytes(array, offset);
|
super.writeBytes(array, offset);
|
||||||
array[offset] = (byte) (sid + ptgClass);
|
array[offset] = (byte) (sid + getPtgClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
public String toFormulaString(HSSFWorkbook book)
|
||||||
{
|
{
|
||||||
return "ERR#";
|
return "ERR#";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
MemErrPtg ptg = new MemErrPtg();
|
|
||||||
ptg.setReserved(getReserved());
|
|
||||||
ptg.setSubexpressionLength(getSubexpressionLength());
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,6 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Ptg.java
|
|
||||||
*
|
|
||||||
* Created on October 28, 2001, 6:30 PM
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
@ -30,22 +24,20 @@ import org.apache.poi.hssf.record.RecordInputStream;
|
|||||||
/**
|
/**
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
*/
|
*/
|
||||||
public class MemFuncPtg extends OperandPtg {
|
public final class MemFuncPtg extends OperandPtg {
|
||||||
|
|
||||||
public final static byte sid = 0x29;
|
public final static byte sid = 0x29;
|
||||||
private short field_1_len_ref_subexpression = 0;
|
private final int field_1_len_ref_subexpression;
|
||||||
|
|
||||||
public MemFuncPtg()
|
|
||||||
{
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
/**Creates new function pointer from a byte array
|
/**Creates new function pointer from a byte array
|
||||||
* usually called while reading an excel file.
|
* usually called while reading an excel file.
|
||||||
*/
|
*/
|
||||||
public MemFuncPtg( RecordInputStream in )
|
public MemFuncPtg(RecordInputStream in) {
|
||||||
{
|
this(in.readUShort());
|
||||||
field_1_len_ref_subexpression = in.readShort();
|
}
|
||||||
|
|
||||||
|
public MemFuncPtg(int subExprLen) {
|
||||||
|
field_1_len_ref_subexpression = subExprLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize()
|
public int getSize()
|
||||||
@ -56,7 +48,7 @@ public class MemFuncPtg extends OperandPtg {
|
|||||||
public void writeBytes( byte[] array, int offset )
|
public void writeBytes( byte[] array, int offset )
|
||||||
{
|
{
|
||||||
array[offset + 0] = sid ;
|
array[offset + 0] = sid ;
|
||||||
LittleEndian.putShort( array, offset + 1, (short)field_1_len_ref_subexpression );
|
LittleEndian.putUShort( array, offset + 1, field_1_len_ref_subexpression );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
public String toFormulaString(HSSFWorkbook book)
|
||||||
@ -66,7 +58,7 @@ public class MemFuncPtg extends OperandPtg {
|
|||||||
|
|
||||||
public byte getDefaultOperandClass()
|
public byte getDefaultOperandClass()
|
||||||
{
|
{
|
||||||
return 0;
|
return Ptg.CLASS_REF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
public int getNumberOfOperands()
|
||||||
@ -74,21 +66,8 @@ public class MemFuncPtg extends OperandPtg {
|
|||||||
return field_1_len_ref_subexpression;
|
return field_1_len_ref_subexpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone()
|
|
||||||
{
|
|
||||||
MemFuncPtg ptg = new MemFuncPtg();
|
|
||||||
ptg.field_1_len_ref_subexpression = this.field_1_len_ref_subexpression;
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLenRefSubexpression()
|
public int getLenRefSubexpression()
|
||||||
{
|
{
|
||||||
return field_1_len_ref_subexpression;
|
return field_1_len_ref_subexpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLenRefSubexpression(int len)
|
|
||||||
{
|
|
||||||
field_1_len_ref_subexpression = (short)len;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -18,7 +18,6 @@
|
|||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Missing Function Arguments
|
* Missing Function Arguments
|
||||||
@ -31,17 +30,11 @@ public final class MissingArgPtg extends ScalarConstantPtg {
|
|||||||
private final static int SIZE = 1;
|
private final static int SIZE = 1;
|
||||||
public final static byte sid = 0x16;
|
public final static byte sid = 0x16;
|
||||||
|
|
||||||
public MissingArgPtg()
|
public static final Ptg instance = new MissingArgPtg();
|
||||||
|
private MissingArgPtg()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public MissingArgPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public void writeBytes(byte [] array, int offset)
|
||||||
{
|
{
|
||||||
array[ offset + 0 ] = sid;
|
array[ offset + 0 ] = sid;
|
||||||
@ -52,14 +45,8 @@ public final class MissingArgPtg extends ScalarConstantPtg {
|
|||||||
return SIZE;
|
return SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
public String toFormulaString(HSSFWorkbook book)
|
||||||
{
|
{
|
||||||
return " ";
|
return " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new MissingArgPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,83 +14,37 @@
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hssf.record.formula;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
package org.apache.poi.hssf.record.formula;
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the standard mathmatical multiplication - *
|
* Implements the standard mathmatical multiplication - *
|
||||||
* @author Andrew C. Oliver (acoliver at apache dot org)
|
* @author Andrew C. Oliver (acoliver at apache dot org)
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class MultiplyPtg extends ValueOperatorPtg {
|
public final class MultiplyPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x05;
|
public final static byte sid = 0x05;
|
||||||
|
|
||||||
/** Creates new AddPtg */
|
public static final ValueOperatorPtg instance = new MultiplyPtg();
|
||||||
|
|
||||||
public MultiplyPtg()
|
private MultiplyPtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiplyPtg(RecordInputStream in)
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public int getNumberOfOperands() {
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStringLength() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return "*";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(Ptg [] operands)
|
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
|
|
||||||
buffer.append(operands[ 0 ].toFormulaString((HSSFWorkbook)null));
|
|
||||||
buffer.append("*");
|
|
||||||
buffer.append(operands[ 1 ].toFormulaString((HSSFWorkbook)null));
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
buffer.append(operands[ 0 ]);
|
buffer.append(operands[ 0 ]);
|
||||||
buffer.append(toFormulaString((HSSFWorkbook)null));
|
buffer.append("*");
|
||||||
buffer.append(operands[ 1 ]);
|
buffer.append(operands[ 1 ]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new MultiplyPtg();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,10 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFName;
|
import org.apache.poi.hssf.usermodel.HSSFName;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.hssf.record.NameRecord;
|
import org.apache.poi.util.LittleEndian;
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -34,12 +33,6 @@ public final class NamePtg extends OperandPtg {
|
|||||||
/** one-based index to defined name record */
|
/** one-based index to defined name record */
|
||||||
private short field_1_label_index;
|
private short field_1_label_index;
|
||||||
private short field_2_zero; // reserved must be 0
|
private short field_2_zero; // reserved must be 0
|
||||||
boolean xtra=false;
|
|
||||||
|
|
||||||
|
|
||||||
private NamePtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new NamePtg and sets its name index to that of the corresponding defined name record
|
* Creates new NamePtg and sets its name index to that of the corresponding defined name record
|
||||||
@ -69,12 +62,9 @@ public final class NamePtg extends OperandPtg {
|
|||||||
|
|
||||||
/** Creates new NamePtg */
|
/** Creates new NamePtg */
|
||||||
|
|
||||||
public NamePtg(RecordInputStream in)
|
public NamePtg(RecordInputStream in) {
|
||||||
{
|
|
||||||
//field_1_ixti = LittleEndian.getShort(data, offset);
|
|
||||||
field_1_label_index = in.readShort();
|
field_1_label_index = in.readShort();
|
||||||
field_2_zero = in.readShort();
|
field_2_zero = in.readShort();
|
||||||
//if (data[offset+6]==0) xtra=true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,15 +74,13 @@ public final class NamePtg extends OperandPtg {
|
|||||||
return field_1_label_index-1; // convert to zero based
|
return field_1_label_index-1; // convert to zero based
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public void writeBytes(byte [] array, int offset) {
|
||||||
{
|
array[offset+0]= (byte) (sid + getPtgClass());
|
||||||
array[offset+0]= (byte) (sid + ptgClass);
|
|
||||||
LittleEndian.putShort(array,offset+1,field_1_label_index);
|
LittleEndian.putShort(array,offset+1,field_1_label_index);
|
||||||
LittleEndian.putShort(array,offset+3, field_2_zero);
|
LittleEndian.putShort(array,offset+3, field_2_zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize()
|
public int getSize() {
|
||||||
{
|
|
||||||
return SIZE;
|
return SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,12 +89,7 @@ public final class NamePtg extends OperandPtg {
|
|||||||
return book.getNameName(field_1_label_index - 1);
|
return book.getNameName(field_1_label_index - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
|
public byte getDefaultOperandClass() {
|
||||||
|
return Ptg.CLASS_REF;
|
||||||
public Object clone() {
|
|
||||||
NamePtg ptg = new NamePtg();
|
|
||||||
ptg.field_1_label_index = field_1_label_index;
|
|
||||||
ptg.field_2_zero = field_2_zero;
|
|
||||||
return ptg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,31 +33,20 @@ public final class NameXPtg extends OperandPtg {
|
|||||||
private short field_3_reserved; // reserved must be 0
|
private short field_3_reserved; // reserved must be 0
|
||||||
|
|
||||||
|
|
||||||
private NameXPtg() {
|
public NameXPtg(RecordInputStream in) {
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates new NamePtg */
|
|
||||||
|
|
||||||
public NameXPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
field_1_ixals = in.readShort();
|
field_1_ixals = in.readShort();
|
||||||
field_2_ilbl = in.readShort();
|
field_2_ilbl = in.readShort();
|
||||||
field_3_reserved = in.readShort();
|
field_3_reserved = in.readShort();
|
||||||
|
|
||||||
//field_2_reserved = LittleEndian.getByteArray(data, offset + 12,12);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public void writeBytes(byte [] array, int offset) {
|
||||||
{
|
array[ offset + 0 ] = (byte)(sid + getPtgClass());
|
||||||
array[ offset + 0 ] = (byte)(sid + ptgClass);
|
|
||||||
LittleEndian.putShort(array, offset + 1, field_1_ixals);
|
LittleEndian.putShort(array, offset + 1, field_1_ixals);
|
||||||
LittleEndian.putShort(array,offset+3, field_2_ilbl);
|
LittleEndian.putShort(array,offset+3, field_2_ilbl);
|
||||||
LittleEndian.putShort(array, offset + 5, field_3_reserved);
|
LittleEndian.putShort(array, offset + 5, field_3_reserved);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize()
|
public int getSize() {
|
||||||
{
|
|
||||||
return SIZE;
|
return SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,14 +56,7 @@ public final class NameXPtg extends OperandPtg {
|
|||||||
return book.resolveNameXText(field_1_ixals, field_2_ilbl-1);
|
return book.resolveNameXText(field_1_ixals, field_2_ilbl-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
|
public byte getDefaultOperandClass() {
|
||||||
|
return Ptg.CLASS_VALUE;
|
||||||
public Object clone() {
|
|
||||||
NameXPtg ptg = new NameXPtg();
|
|
||||||
ptg.field_1_ixals = field_1_ixals;
|
|
||||||
ptg.field_3_reserved = field_3_reserved;
|
|
||||||
ptg.field_2_ilbl = field_2_ilbl;
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -18,70 +17,36 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ptg class to implement not equal
|
* Ptg class to implement not equal
|
||||||
*
|
*
|
||||||
* @author fred at stsci dot edu
|
* @author fred at stsci dot edu
|
||||||
*/
|
*/
|
||||||
public final class NotEqualPtg extends ValueOperatorPtg {
|
public final class NotEqualPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x0e;
|
public final static byte sid = 0x0e;
|
||||||
|
|
||||||
/**
|
public static final ValueOperatorPtg instance = new NotEqualPtg();
|
||||||
* Creates new NotEqualPtg
|
|
||||||
*/
|
private NotEqualPtg() {
|
||||||
public NotEqualPtg()
|
// enforce singleton
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public NotEqualPtg( RecordInputStream in )
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes( byte[] array, int offset )
|
public int getNumberOfOperands() {
|
||||||
{
|
|
||||||
array[offset + 0] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString( HSSFWorkbook book )
|
public String toFormulaString(String[] operands) {
|
||||||
{
|
|
||||||
return "<>";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString( String[] operands )
|
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
buffer.append( operands[0] );
|
buffer.append( operands[0] );
|
||||||
|
|
||||||
buffer.append( toFormulaString( (HSSFWorkbook) null ) );
|
buffer.append("<>");
|
||||||
buffer.append( operands[1] );
|
buffer.append( operands[1] );
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone()
|
|
||||||
{
|
|
||||||
return new NotEqualPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,16 +31,12 @@ import org.apache.poi.hssf.record.RecordInputStream;
|
|||||||
public final class NumberPtg extends ScalarConstantPtg {
|
public final class NumberPtg extends ScalarConstantPtg {
|
||||||
public final static int SIZE = 9;
|
public final static int SIZE = 9;
|
||||||
public final static byte sid = 0x1f;
|
public final static byte sid = 0x1f;
|
||||||
private double field_1_value;
|
private final double field_1_value;
|
||||||
|
|
||||||
private NumberPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create a NumberPtg from a byte array read from disk */
|
/** Create a NumberPtg from a byte array read from disk */
|
||||||
public NumberPtg(RecordInputStream in)
|
public NumberPtg(RecordInputStream in)
|
||||||
{
|
{
|
||||||
setValue(in.readDouble());
|
field_1_value = in.readDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a NumberPtg from a string representation of the number
|
/** Create a NumberPtg from a string representation of the number
|
||||||
@ -49,13 +45,7 @@ public final class NumberPtg extends ScalarConstantPtg {
|
|||||||
* @param value : String representation of a floating point number
|
* @param value : String representation of a floating point number
|
||||||
*/
|
*/
|
||||||
public NumberPtg(String value) {
|
public NumberPtg(String value) {
|
||||||
setValue(Double.parseDouble(value));
|
field_1_value = Double.parseDouble(value);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setValue(double value)
|
|
||||||
{
|
|
||||||
field_1_value = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -79,10 +69,4 @@ public final class NumberPtg extends ScalarConstantPtg {
|
|||||||
{
|
{
|
||||||
return "" + getValue();
|
return "" + getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
NumberPtg ptg = new NumberPtg();
|
|
||||||
ptg.field_1_value = field_1_value;
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,21 +17,15 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* defines a Ptg that is an operation instead of an operand
|
* defines a Ptg that is an operation instead of an operand
|
||||||
* @author andy
|
* @author andy
|
||||||
*/
|
*/
|
||||||
|
public abstract class OperationPtg extends Ptg {
|
||||||
public abstract class OperationPtg extends Ptg
|
|
||||||
{
|
|
||||||
public final static int TYPE_UNARY = 0;
|
public final static int TYPE_UNARY = 0;
|
||||||
public final static int TYPE_BINARY = 1;
|
public final static int TYPE_BINARY = 1;
|
||||||
public final static int TYPE_FUNCTION = 2;
|
public final static int TYPE_FUNCTION = 2;
|
||||||
|
|
||||||
public abstract int getType();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a string representation of the operations
|
* returns a string representation of the operations
|
||||||
* the length of the input array should equal the number returned by
|
* the length of the input array should equal the number returned by
|
||||||
@ -45,6 +39,12 @@ public abstract class OperationPtg extends Ptg
|
|||||||
*/
|
*/
|
||||||
public abstract int getNumberOfOperands();
|
public abstract int getNumberOfOperands();
|
||||||
|
|
||||||
public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
|
public byte getDefaultOperandClass() {
|
||||||
|
return Ptg.CLASS_VALUE;
|
||||||
|
}
|
||||||
|
public final int getType() {
|
||||||
|
// TODO remove "int getType();" from Eval hierarchy
|
||||||
|
throw new RuntimeException("remove this method");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,18 +37,11 @@ public final class ParenthesisPtg extends ControlPtg {
|
|||||||
private final static int SIZE = 1;
|
private final static int SIZE = 1;
|
||||||
public final static byte sid = 0x15;
|
public final static byte sid = 0x15;
|
||||||
|
|
||||||
public ParenthesisPtg()
|
public static final ControlPtg instance = new ParenthesisPtg();
|
||||||
{
|
private ParenthesisPtg() {
|
||||||
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParenthesisPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public void writeBytes(byte [] array, int offset)
|
||||||
{
|
{
|
||||||
array[ offset + 0 ] = sid;
|
array[ offset + 0 ] = sid;
|
||||||
@ -68,9 +61,4 @@ public final class ParenthesisPtg extends ControlPtg {
|
|||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
return "("+operands[0]+")";
|
return "("+operands[0]+")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new ParenthesisPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/* ====================================================================
|
/* ====================================================================
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -16,68 +15,33 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
/*
|
|
||||||
* PercentPtg.java
|
|
||||||
*
|
|
||||||
* Created on March 29, 2006, 9:23 PM
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Percent PTG.
|
* Percent PTG.
|
||||||
*
|
*
|
||||||
* @author Daniel Noll (daniel at nuix.com.au)
|
* @author Daniel Noll (daniel at nuix.com.au)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class PercentPtg extends ValueOperatorPtg {
|
public final class PercentPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
public final static int SIZE = 1;
|
||||||
public final static byte sid = 0x14;
|
public final static byte sid = 0x14;
|
||||||
|
|
||||||
private final static String PERCENT = "%";
|
private final static String PERCENT = "%";
|
||||||
|
|
||||||
/** Creates new PercentPtg */
|
public static final ValueOperatorPtg instance = new PercentPtg();
|
||||||
|
|
||||||
public PercentPtg()
|
private PercentPtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public PercentPtg(RecordInputStream in)
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumberOfOperands() {
|
||||||
public void writeBytes(byte [] array, int offset)
|
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_UNARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Implementation of method from Ptg */
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return "%";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** implementation of method from OperationsPtg*/
|
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
@ -85,9 +49,4 @@ public final class PercentPtg extends ValueOperatorPtg {
|
|||||||
buffer.append(PERCENT);
|
buffer.append(PERCENT);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new PercentPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,53 +17,26 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author andy
|
* @author andy
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
public final class PowerPtg extends ValueOperatorPtg {
|
public final class PowerPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x07;
|
public final static byte sid = 0x07;
|
||||||
|
|
||||||
/** Creates new AddPtg */
|
public static final ValueOperatorPtg instance = new PowerPtg();
|
||||||
|
|
||||||
public PowerPtg()
|
private PowerPtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public PowerPtg(RecordInputStream in)
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public int getNumberOfOperands() {
|
||||||
{
|
return 2; // TODO - 2 seems wrong (Jun 2008). Maybe this method is not relevant
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return "^";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
@ -71,13 +44,8 @@ public final class PowerPtg extends ValueOperatorPtg {
|
|||||||
|
|
||||||
|
|
||||||
buffer.append(operands[ 0 ]);
|
buffer.append(operands[ 0 ]);
|
||||||
buffer.append(toFormulaString((HSSFWorkbook)null));
|
buffer.append("^");
|
||||||
buffer.append(operands[ 1 ]);
|
buffer.append(operands[ 1 ]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new PowerPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,22 +17,30 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* <tt>Ptg</tt> represents a syntactic token in a formula. 'PTG' is an acronym for
|
||||||
|
* '<b>p</b>arse <b>t</b>hin<b>g</b>'. Originally, the name referred to the single
|
||||||
|
* byte identifier at the start of the token, but in POI, <tt>Ptg</tt> encapsulates
|
||||||
|
* the whole formula token (initial byte + value data).
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* <tt>Ptg</tt>s are logically arranged in a tree representing the structure of the
|
||||||
|
* parsed formula. However, in BIFF files <tt>Ptg</tt>s are written/read in
|
||||||
|
* <em>Reverse-Polish Notation</em> order. The RPN ordering also simplifies formula
|
||||||
|
* evaluation logic, so POI mostly accesses <tt>Ptg</tt>s in the same way.
|
||||||
*
|
*
|
||||||
* @author andy
|
* @author andy
|
||||||
* @author avik
|
* @author avik
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
public abstract class Ptg
|
public abstract class Ptg implements Cloneable {
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/* convert infix order ptg list to rpn order ptg list
|
/* convert infix order ptg list to rpn order ptg list
|
||||||
* @return List ptgs in RPN order
|
* @return List ptgs in RPN order
|
||||||
@ -91,6 +99,14 @@ public abstract class Ptg
|
|||||||
* Reads <tt>size</tt> bytes of the input stream, to create an array of <tt>Ptg</tt>s.
|
* Reads <tt>size</tt> bytes of the input stream, to create an array of <tt>Ptg</tt>s.
|
||||||
* Extra data (beyond <tt>size</tt>) may be read if and <tt>ArrayPtg</tt>s are present.
|
* Extra data (beyond <tt>size</tt>) may be read if and <tt>ArrayPtg</tt>s are present.
|
||||||
*/
|
*/
|
||||||
|
public static Ptg[] readTokens(int size, RecordInputStream in) {
|
||||||
|
Stack temp = createParsedExpressionTokens((short)size, in);
|
||||||
|
return toPtgArray(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated - use readTokens()
|
||||||
|
*/
|
||||||
public static Stack createParsedExpressionTokens(short size, RecordInputStream in)
|
public static Stack createParsedExpressionTokens(short size, RecordInputStream in)
|
||||||
{
|
{
|
||||||
Stack stack = new Stack();
|
Stack stack = new Stack();
|
||||||
@ -137,7 +153,6 @@ public abstract class Ptg
|
|||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Ptg createClassifiedPtg(byte id, RecordInputStream in) {
|
private static Ptg createClassifiedPtg(byte id, RecordInputStream in) {
|
||||||
@ -145,15 +160,19 @@ public abstract class Ptg
|
|||||||
int baseId = id & 0x1F | 0x20;
|
int baseId = id & 0x1F | 0x20;
|
||||||
|
|
||||||
switch (baseId) {
|
switch (baseId) {
|
||||||
|
case ArrayPtg.sid: return new ArrayPtg(in); // 0x20, 0x40, 0x60
|
||||||
case FuncPtg.sid: return new FuncPtg(in); // 0x21, 0x41, 0x61
|
case FuncPtg.sid: return new FuncPtg(in); // 0x21, 0x41, 0x61
|
||||||
case FuncVarPtg.sid: return new FuncVarPtg(in); // 0x22, 0x42, 0x62
|
case FuncVarPtg.sid: return new FuncVarPtg(in); // 0x22, 0x42, 0x62
|
||||||
case NamePtg.sid: return new NamePtg(in); // 0x23, 0x43, 0x63
|
case NamePtg.sid: return new NamePtg(in); // 0x23, 0x43, 0x63
|
||||||
|
case RefPtg.sid: return new RefPtg(in); // 0x24, 0x44, 0x64
|
||||||
|
case AreaPtg.sid: return new AreaPtg(in); // 0x25, 0x45, 0x65
|
||||||
case MemAreaPtg.sid: return new MemAreaPtg(in); // 0x26, 0x46, 0x66
|
case MemAreaPtg.sid: return new MemAreaPtg(in); // 0x26, 0x46, 0x66
|
||||||
case MemErrPtg.sid: return new MemErrPtg(in); // 0x27, 0x47, 0x67
|
case MemErrPtg.sid: return new MemErrPtg(in); // 0x27, 0x47, 0x67
|
||||||
case MemFuncPtg.sid: return new MemFuncPtg(in); // 0x29, 0x49, 0x69
|
case MemFuncPtg.sid: return new MemFuncPtg(in); // 0x29, 0x49, 0x69
|
||||||
case RefErrorPtg.sid: return new RefErrorPtg(in);// 0x2a, 0x4a, 0x6a
|
case RefErrorPtg.sid: return new RefErrorPtg(in);// 0x2a, 0x4a, 0x6a
|
||||||
case AreaErrPtg.sid: return new AreaErrPtg(in); // 0x2b, 0x4b, 0x6b
|
case AreaErrPtg.sid: return new AreaErrPtg(in); // 0x2b, 0x4b, 0x6b
|
||||||
|
case RefNPtg.sid: return new RefNPtg(in); // 0x2c, 0x4c, 0x6c
|
||||||
|
case AreaNPtg.sid: return new AreaNPtg(in); // 0x2d, 0x4d, 0x6d
|
||||||
|
|
||||||
case NameXPtg.sid: return new NameXPtg(in); // 0x39, 0x49, 0x79
|
case NameXPtg.sid: return new NameXPtg(in); // 0x39, 0x49, 0x79
|
||||||
case Ref3DPtg.sid: return new Ref3DPtg(in); // 0x3a, 0x5a, 0x7a
|
case Ref3DPtg.sid: return new Ref3DPtg(in); // 0x3a, 0x5a, 0x7a
|
||||||
@ -161,31 +180,6 @@ public abstract class Ptg
|
|||||||
case DeletedRef3DPtg.sid: return new DeletedRef3DPtg(in); // 0x3c, 0x5c, 0x7c
|
case DeletedRef3DPtg.sid: return new DeletedRef3DPtg(in); // 0x3c, 0x5c, 0x7c
|
||||||
case DeletedArea3DPtg.sid: return new DeletedArea3DPtg(in); // 0x3d, 0x5d, 0x7d
|
case DeletedArea3DPtg.sid: return new DeletedArea3DPtg(in); // 0x3d, 0x5d, 0x7d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (id) {
|
|
||||||
// TODO - why are specific subclasses needed for these Ptgs?
|
|
||||||
case ArrayPtg.sid: return new ArrayPtg(in); // 0x20
|
|
||||||
case ArrayPtgV.sid: return new ArrayPtgV(in); // 0x40
|
|
||||||
case ArrayPtgA.sid: return new ArrayPtgA(in); // 0x60
|
|
||||||
|
|
||||||
case ReferencePtg.sid: return new ReferencePtg(in);// 0x24
|
|
||||||
case RefAPtg.sid: return new RefAPtg(in); // 0x64
|
|
||||||
case RefVPtg.sid: return new RefVPtg(in); // 0x44
|
|
||||||
|
|
||||||
case RefNAPtg.sid: return new RefNAPtg(in); // 0x6C
|
|
||||||
case RefNPtg.sid: return new RefNPtg(in); // 0x2C
|
|
||||||
case RefNVPtg.sid: return new RefNVPtg(in); // 0x4C
|
|
||||||
|
|
||||||
case AreaPtg.sid: return new AreaPtg(in); // 0x25
|
|
||||||
case AreaVPtg.sid: return new AreaVPtg(in); // 0x45
|
|
||||||
case AreaAPtg.sid: return new AreaAPtg(in); // 0x65
|
|
||||||
|
|
||||||
case AreaNAPtg.sid: return new AreaNAPtg(in); // 0x6D
|
|
||||||
case AreaNPtg.sid: return new AreaNPtg(in); // 0x2D
|
|
||||||
case AreaNVPtg.sid: return new AreaNVPtg(in); // 0x4D
|
|
||||||
|
|
||||||
}
|
|
||||||
throw new UnsupportedOperationException(" Unknown Ptg in Formula: 0x"+
|
throw new UnsupportedOperationException(" Unknown Ptg in Formula: 0x"+
|
||||||
Integer.toHexString(id) + " (" + ( int ) id + ")");
|
Integer.toHexString(id) + " (" + ( int ) id + ")");
|
||||||
}
|
}
|
||||||
@ -194,26 +188,27 @@ public abstract class Ptg
|
|||||||
switch(id) {
|
switch(id) {
|
||||||
case 0x00: return new UnknownPtg(); // TODO - not a real Ptg
|
case 0x00: return new UnknownPtg(); // TODO - not a real Ptg
|
||||||
case ExpPtg.sid: return new ExpPtg(in); // 0x01
|
case ExpPtg.sid: return new ExpPtg(in); // 0x01
|
||||||
case AddPtg.sid: return new AddPtg(in); // 0x03
|
case AddPtg.sid: return AddPtg.instance; // 0x03
|
||||||
case SubtractPtg.sid: return new SubtractPtg(in); // 0x04
|
case SubtractPtg.sid: return SubtractPtg.instance; // 0x04
|
||||||
case MultiplyPtg.sid: return new MultiplyPtg(in); // 0x05
|
case MultiplyPtg.sid: return MultiplyPtg.instance; // 0x05
|
||||||
case DividePtg.sid: return new DividePtg(in); // 0x06
|
case DividePtg.sid: return DividePtg.instance; // 0x06
|
||||||
case PowerPtg.sid: return new PowerPtg(in); // 0x07
|
case PowerPtg.sid: return PowerPtg.instance; // 0x07
|
||||||
case ConcatPtg.sid: return new ConcatPtg(in); // 0x08
|
case ConcatPtg.sid: return ConcatPtg.instance; // 0x08
|
||||||
case LessThanPtg.sid: return new LessThanPtg(in); // 0x09
|
case LessThanPtg.sid: return LessThanPtg.instance; // 0x09
|
||||||
case LessEqualPtg.sid: return new LessEqualPtg(in); // 0x0a
|
case LessEqualPtg.sid: return LessEqualPtg.instance; // 0x0a
|
||||||
case EqualPtg.sid: return new EqualPtg(in); // 0x0b
|
case EqualPtg.sid: return EqualPtg.instance; // 0x0b
|
||||||
case GreaterEqualPtg.sid: return new GreaterEqualPtg(in);// 0x0c
|
case GreaterEqualPtg.sid: return GreaterEqualPtg.instance;// 0x0c
|
||||||
case GreaterThanPtg.sid: return new GreaterThanPtg(in); // 0x0d
|
case GreaterThanPtg.sid: return GreaterThanPtg.instance; // 0x0d
|
||||||
case NotEqualPtg.sid: return new NotEqualPtg(in); // 0x0e
|
case NotEqualPtg.sid: return NotEqualPtg.instance; // 0x0e
|
||||||
case IntersectionPtg.sid: return new IntersectionPtg(in);// 0x0f
|
case IntersectionPtg.sid: return IntersectionPtg.instance;// 0x0f
|
||||||
case UnionPtg.sid: return new UnionPtg(in); // 0x10
|
case UnionPtg.sid: return UnionPtg.instance; // 0x10
|
||||||
case RangePtg.sid: return new RangePtg(in); // 0x11
|
case RangePtg.sid: return RangePtg.instance; // 0x11
|
||||||
case UnaryPlusPtg.sid: return new UnaryPlusPtg(in); // 0x12
|
case UnaryPlusPtg.sid: return UnaryPlusPtg.instance; // 0x12
|
||||||
case UnaryMinusPtg.sid: return new UnaryMinusPtg(in); // 0x13
|
case UnaryMinusPtg.sid: return UnaryMinusPtg.instance; // 0x13
|
||||||
case PercentPtg.sid: return new PercentPtg(in); // 0x14
|
case PercentPtg.sid: return PercentPtg.instance; // 0x14
|
||||||
case ParenthesisPtg.sid: return new ParenthesisPtg(in); // 0x15
|
case ParenthesisPtg.sid: return ParenthesisPtg.instance; // 0x15
|
||||||
case MissingArgPtg.sid: return new MissingArgPtg(in); // 0x16
|
case MissingArgPtg.sid: return MissingArgPtg.instance; // 0x16
|
||||||
|
|
||||||
case StringPtg.sid: return new StringPtg(in); // 0x17
|
case StringPtg.sid: return new StringPtg(in); // 0x17
|
||||||
case AttrPtg.sid:
|
case AttrPtg.sid:
|
||||||
case 0x1a: return new AttrPtg(in); // 0x19
|
case 0x1a: return new AttrPtg(in); // 0x19
|
||||||
@ -231,6 +226,28 @@ public abstract class Ptg
|
|||||||
public static int getEncodedSize(Stack ptgs) {
|
public static int getEncodedSize(Stack ptgs) {
|
||||||
return getEncodedSize(toPtgArray(ptgs));
|
return getEncodedSize(toPtgArray(ptgs));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @return a distinct copy of this <tt>Ptg</tt> if the class is mutable, or the same instance
|
||||||
|
* if the class is immutable.
|
||||||
|
*/
|
||||||
|
public final Ptg copy() {
|
||||||
|
// TODO - all base tokens are logically immutable, but AttrPtg needs some clean-up
|
||||||
|
if (this instanceof ValueOperatorPtg) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
if (this instanceof ScalarConstantPtg) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return (Ptg) clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Object clone() {
|
||||||
|
try {
|
||||||
|
return super.clone();
|
||||||
|
} catch (CloneNotSupportedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
private static Ptg[] toPtgArray(List l) {
|
private static Ptg[] toPtgArray(List l) {
|
||||||
Ptg[] result = new Ptg[l.size()];
|
Ptg[] result = new Ptg[l.size()];
|
||||||
l.toArray(result);
|
l.toArray(result);
|
||||||
@ -251,7 +268,20 @@ public abstract class Ptg
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Writes the ptgs to the data buffer, starting at the specified offset.
|
||||||
|
*
|
||||||
|
* <br/>
|
||||||
|
* The 2 byte encode length field is <b>not</b> written by this method.
|
||||||
|
* @return number of bytes written
|
||||||
|
*/
|
||||||
|
public static int serializePtgs(Ptg[] ptgs, byte[] data, int offset) {
|
||||||
|
return serializePtgStack(createStack(ptgs), data, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use serializePtgs()
|
||||||
|
*/
|
||||||
public static int serializePtgStack(Stack expression, byte[] array, int offset) {
|
public static int serializePtgStack(Stack expression, byte[] array, int offset) {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
@ -308,7 +338,7 @@ public abstract class Ptg
|
|||||||
/**
|
/**
|
||||||
* dump a debug representation (hexdump) to a string
|
* dump a debug representation (hexdump) to a string
|
||||||
*/
|
*/
|
||||||
public String toDebugString() {
|
public final String toDebugString() {
|
||||||
byte[] ba = new byte[getSize()];
|
byte[] ba = new byte[getSize()];
|
||||||
String retval=null;
|
String retval=null;
|
||||||
writeBytes(ba,0);
|
writeBytes(ba,0);
|
||||||
@ -332,9 +362,9 @@ public abstract class Ptg
|
|||||||
public static final byte CLASS_VALUE = 0x20;
|
public static final byte CLASS_VALUE = 0x20;
|
||||||
public static final byte CLASS_ARRAY = 0x40;
|
public static final byte CLASS_ARRAY = 0x40;
|
||||||
|
|
||||||
protected byte ptgClass = CLASS_REF; //base ptg
|
private byte ptgClass = CLASS_REF; //base ptg
|
||||||
|
|
||||||
public void setClass(byte thePtgClass) {
|
public final void setClass(byte thePtgClass) {
|
||||||
if (isBaseToken()) {
|
if (isBaseToken()) {
|
||||||
throw new RuntimeException("setClass should not be called on a base token");
|
throw new RuntimeException("setClass should not be called on a base token");
|
||||||
}
|
}
|
||||||
@ -344,15 +374,12 @@ public abstract class Ptg
|
|||||||
/**
|
/**
|
||||||
* @return the 'operand class' (REF/VALUE/ARRAY) for this Ptg
|
* @return the 'operand class' (REF/VALUE/ARRAY) for this Ptg
|
||||||
*/
|
*/
|
||||||
public byte getPtgClass() {
|
public final byte getPtgClass() {
|
||||||
return ptgClass;
|
return ptgClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract byte getDefaultOperandClass();
|
public abstract byte getDefaultOperandClass();
|
||||||
|
|
||||||
public abstract Object clone();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return <code>false</code> if this token is classified as 'reference', 'value', or 'array'
|
* @return <code>false</code> if this token is classified as 'reference', 'value', or 'array'
|
||||||
*/
|
*/
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Daniel Noll (daniel at nuix dot com dot au)
|
* @author Daniel Noll (daniel at nuix dot com dot au)
|
||||||
@ -27,20 +26,16 @@ public final class RangePtg extends OperationPtg {
|
|||||||
public final static int SIZE = 1;
|
public final static int SIZE = 1;
|
||||||
public final static byte sid = 0x11;
|
public final static byte sid = 0x11;
|
||||||
|
|
||||||
public RangePtg()
|
public static final OperationPtg instance = new RangePtg();
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public RangePtg(RecordInputStream in)
|
private RangePtg() {
|
||||||
{
|
// enforce singleton
|
||||||
// No contents
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isBaseToken() {
|
public final boolean isBaseToken() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getSize()
|
public int getSize()
|
||||||
{
|
{
|
||||||
return SIZE;
|
return SIZE;
|
||||||
@ -51,17 +46,6 @@ public final class RangePtg extends OperationPtg {
|
|||||||
array[ offset + 0 ] = sid;
|
array[ offset + 0 ] = sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone()
|
|
||||||
{
|
|
||||||
return new RangePtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implementation of method from Ptg */
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
public String toFormulaString(HSSFWorkbook book)
|
||||||
{
|
{
|
||||||
return ":";
|
return ":";
|
||||||
|
@ -82,7 +82,7 @@ public class Ref3DPtg extends OperandPtg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset) {
|
public void writeBytes(byte [] array, int offset) {
|
||||||
array[ 0 + offset ] = (byte) (sid + ptgClass);
|
array[ 0 + offset ] = (byte) (sid + getPtgClass());
|
||||||
LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
|
LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
|
||||||
LittleEndian.putShort(array, 3 + offset , (short)getRow());
|
LittleEndian.putShort(array, 3 + offset , (short)getRow());
|
||||||
LittleEndian.putShort(array, 5 + offset , (short)getColumnRaw());
|
LittleEndian.putShort(array, 5 + offset , (short)getColumnRaw());
|
||||||
@ -190,14 +190,7 @@ public class Ref3DPtg extends OperandPtg {
|
|||||||
return retval.toString();
|
return retval.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getDefaultOperandClass() {return Ptg.CLASS_REF;}
|
public byte getDefaultOperandClass() {
|
||||||
|
return Ptg.CLASS_REF;
|
||||||
public Object clone() {
|
|
||||||
Ref3DPtg ptg = new Ref3DPtg();
|
|
||||||
ptg.field_1_index_extern_sheet = field_1_index_extern_sheet;
|
|
||||||
ptg.field_2_row = field_2_row;
|
|
||||||
ptg.field_3_column = field_3_column;
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,9 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.util.LittleEndian;
|
|
||||||
import org.apache.poi.util.BitField;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.util.CellReference;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RefError - handles deleted cell reference
|
* RefError - handles deleted cell reference
|
||||||
@ -34,10 +31,6 @@ public final class RefErrorPtg extends OperandPtg {
|
|||||||
public final static byte sid = 0x2a;
|
public final static byte sid = 0x2a;
|
||||||
private int field_1_reserved;
|
private int field_1_reserved;
|
||||||
|
|
||||||
private RefErrorPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public RefErrorPtg(RecordInputStream in)
|
public RefErrorPtg(RecordInputStream in)
|
||||||
{
|
{
|
||||||
field_1_reserved = in.readInt();
|
field_1_reserved = in.readInt();
|
||||||
@ -54,7 +47,7 @@ public final class RefErrorPtg extends OperandPtg {
|
|||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public void writeBytes(byte [] array, int offset)
|
||||||
{
|
{
|
||||||
array[offset] = (byte) (sid + ptgClass);
|
array[offset] = (byte) (sid + getPtgClass());
|
||||||
LittleEndian.putInt(array,offset+1,field_1_reserved);
|
LittleEndian.putInt(array,offset+1,field_1_reserved);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,11 +75,4 @@ public final class RefErrorPtg extends OperandPtg {
|
|||||||
public byte getDefaultOperandClass() {
|
public byte getDefaultOperandClass() {
|
||||||
return Ptg.CLASS_REF;
|
return Ptg.CLASS_REF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
RefErrorPtg ptg = new RefErrorPtg();
|
|
||||||
ptg.field_1_reserved = field_1_reserved;
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RefNAPtg
|
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
|
||||||
*/
|
|
||||||
public final class RefNAPtg extends ReferencePtg
|
|
||||||
{
|
|
||||||
public final static byte sid = 0x6C;
|
|
||||||
|
|
||||||
protected RefNAPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
public RefNAPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
super(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRefPtgName() {
|
|
||||||
return "RefNAPtg";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,37 +18,21 @@
|
|||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RefNPtg
|
* RefNPtg
|
||||||
* @author Jason Height (jheight at apache dot com)
|
* @author Jason Height (jheight at apache dot com)
|
||||||
*/
|
*/
|
||||||
public final class RefNPtg extends ReferencePtg
|
public final class RefNPtg extends RefPtgBase {
|
||||||
{
|
|
||||||
public final static byte sid = 0x2C;
|
public final static byte sid = 0x2C;
|
||||||
|
|
||||||
protected RefNPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates new ValueReferencePtg */
|
/** Creates new ValueReferencePtg */
|
||||||
|
|
||||||
public RefNPtg(RecordInputStream in)
|
public RefNPtg(RecordInputStream in) {
|
||||||
{
|
|
||||||
super(in);
|
super(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRefPtgName() {
|
protected byte getSid() {
|
||||||
return "RefNPtg";
|
return sid;
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RefNVPtg
|
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
|
||||||
*/
|
|
||||||
|
|
||||||
public final class RefNVPtg extends ReferencePtg {
|
|
||||||
public final static byte sid = 0x4C;
|
|
||||||
|
|
||||||
protected RefNVPtg() {
|
|
||||||
//Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates new ValueReferencePtg */
|
|
||||||
|
|
||||||
public RefNVPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
super(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRefPtgName() {
|
|
||||||
return "RefNVPtg";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
throw notImplemented();
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,36 +20,34 @@ package org.apache.poi.hssf.record.formula;
|
|||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RefNAPtg
|
* ReferencePtg - handles references (such as A1, A2, IA4)
|
||||||
|
* @author Andrew C. Oliver (acoliver@apache.org)
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
|
public final class RefPtg extends RefPtgBase {
|
||||||
|
public final static byte sid = 0x24;
|
||||||
|
|
||||||
public final class RefAPtg extends ReferencePtg {
|
/**
|
||||||
public final static byte sid = 0x64;
|
* Takes in a String representation of a cell reference and fills out the
|
||||||
|
* numeric fields.
|
||||||
protected RefAPtg() {
|
*/
|
||||||
super();
|
public RefPtg(String cellref) {
|
||||||
|
super(cellref);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefAPtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
|
public RefPtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
|
||||||
super(row, column, isRowRelative, isColumnRelative);
|
setRow(row);
|
||||||
|
setColumn(column);
|
||||||
|
setRowRelative(isRowRelative);
|
||||||
|
setColRelative(isColumnRelative);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefAPtg(RecordInputStream in)
|
public RefPtg(RecordInputStream in) {
|
||||||
{
|
|
||||||
super(in);
|
super(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected byte getSid() {
|
||||||
public String getRefPtgName() {
|
return sid;
|
||||||
return "RefAPtg";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
RefAPtg ptg = new RefAPtg();
|
|
||||||
ptg.setRow(getRow());
|
|
||||||
ptg.setColumnRaw(getColumnRaw());
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -26,26 +26,13 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
import org.apache.poi.hssf.record.RecordInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ReferencePtg - handles references (such as A1, A2, IA4)
|
* ReferencePtgBase - handles references (such as A1, A2, IA4)
|
||||||
* @author Andrew C. Oliver (acoliver@apache.org)
|
* @author Andrew C. Oliver (acoliver@apache.org)
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
public class ReferencePtg extends OperandPtg {
|
public abstract class RefPtgBase extends OperandPtg {
|
||||||
/**
|
|
||||||
* TODO - (May-2008) fix subclasses of ReferencePtg 'RefN~' which are used in shared formulas.
|
|
||||||
* (See bugzilla 44921)
|
|
||||||
* The 'RefN~' instances do not work properly, and are expected to be converted by
|
|
||||||
* SharedFormulaRecord.convertSharedFormulas().
|
|
||||||
* This conversion currently does not take place for formulas of named ranges, conditional
|
|
||||||
* format rules and data validation rules.
|
|
||||||
* Furthermore, conversion is probably not appropriate in those instances.
|
|
||||||
*/
|
|
||||||
protected final RuntimeException notImplemented() {
|
|
||||||
return new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
|
|
||||||
}
|
|
||||||
|
|
||||||
private final static int SIZE = 5;
|
private final static int SIZE = 5;
|
||||||
public final static byte sid = 0x24;
|
|
||||||
private final static int MAX_ROW_NUMBER = 65536;
|
private final static int MAX_ROW_NUMBER = 65536;
|
||||||
|
|
||||||
/** The row index - zero based unsigned 16 bit value */
|
/** The row index - zero based unsigned 16 bit value */
|
||||||
@ -60,15 +47,15 @@ public class ReferencePtg extends OperandPtg {
|
|||||||
private static final BitField colRelative = BitFieldFactory.getInstance(0x4000);
|
private static final BitField colRelative = BitFieldFactory.getInstance(0x4000);
|
||||||
private static final BitField column = BitFieldFactory.getInstance(0x00FF);
|
private static final BitField column = BitFieldFactory.getInstance(0x00FF);
|
||||||
|
|
||||||
protected ReferencePtg() {
|
protected RefPtgBase() {
|
||||||
//Required for clone methods
|
//Required for clone methods
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes in a String represnetation of a cell reference and fills out the
|
* Takes in a String representation of a cell reference and fills out the
|
||||||
* numeric fields.
|
* numeric fields.
|
||||||
*/
|
*/
|
||||||
public ReferencePtg(String cellref) {
|
protected RefPtgBase(String cellref) {
|
||||||
CellReference c= new CellReference(cellref);
|
CellReference c= new CellReference(cellref);
|
||||||
setRow(c.getRow());
|
setRow(c.getRow());
|
||||||
setColumn(c.getCol());
|
setColumn(c.getCol());
|
||||||
@ -76,26 +63,19 @@ public class ReferencePtg extends OperandPtg {
|
|||||||
setRowRelative(!c.isRowAbsolute());
|
setRowRelative(!c.isRowAbsolute());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReferencePtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
|
protected RefPtgBase(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
|
||||||
setRow(row);
|
setRow(row);
|
||||||
setColumn(column);
|
setColumn(column);
|
||||||
setRowRelative(isRowRelative);
|
setRowRelative(isRowRelative);
|
||||||
setColRelative(isColumnRelative);
|
setColRelative(isColumnRelative);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates new ValueReferencePtg */
|
protected RefPtgBase(RecordInputStream in) {
|
||||||
|
|
||||||
public ReferencePtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
field_1_row = in.readUShort();
|
field_1_row = in.readUShort();
|
||||||
field_2_col = in.readUShort();
|
field_2_col = in.readUShort();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRefPtgName() {
|
public final String toString() {
|
||||||
return "ReferencePtg";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
CellReference cr = new CellReference(getRow(), getColumn(), !isRowRelative(),!isColRelative());
|
CellReference cr = new CellReference(getRow(), getColumn(), !isRowRelative(),!isColRelative());
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
sb.append(getClass().getName());
|
sb.append(getClass().getName());
|
||||||
@ -105,16 +85,16 @@ public class ReferencePtg extends OperandPtg {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public final void writeBytes(byte [] array, int offset) {
|
||||||
{
|
array[offset] = (byte) (getSid() + getPtgClass());
|
||||||
array[offset] = (byte) (sid + ptgClass);
|
|
||||||
|
|
||||||
LittleEndian.putShort(array, offset+1, (short)field_1_row);
|
LittleEndian.putShort(array, offset+1, (short)field_1_row);
|
||||||
LittleEndian.putShort(array, offset+3, (short)field_2_col);
|
LittleEndian.putShort(array, offset+3, (short)field_2_col);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRow(int row)
|
protected abstract byte getSid();
|
||||||
{
|
|
||||||
|
public final void setRow(int row) {
|
||||||
if(row < 0 || row >= MAX_ROW_NUMBER) {
|
if(row < 0 || row >= MAX_ROW_NUMBER) {
|
||||||
throw new IllegalArgumentException("The row number, when specified as an integer, must be between 0 and " + MAX_ROW_NUMBER);
|
throw new IllegalArgumentException("The row number, when specified as an integer, must be between 0 and " + MAX_ROW_NUMBER);
|
||||||
}
|
}
|
||||||
@ -125,81 +105,61 @@ public class ReferencePtg extends OperandPtg {
|
|||||||
* Returns the row number as a short, which will be
|
* Returns the row number as a short, which will be
|
||||||
* wrapped (negative) for values between 32769 and 65535
|
* wrapped (negative) for values between 32769 and 65535
|
||||||
*/
|
*/
|
||||||
public int getRow()
|
public final int getRow(){
|
||||||
{
|
|
||||||
return field_1_row;
|
return field_1_row;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns the row number as an int, between 0 and 65535
|
* Returns the row number as an int, between 0 and 65535
|
||||||
*/
|
*/
|
||||||
public int getRowAsInt()
|
public final int getRowAsInt() {
|
||||||
{
|
|
||||||
if(field_1_row < 0) {
|
|
||||||
return field_1_row + MAX_ROW_NUMBER;
|
|
||||||
}
|
|
||||||
return field_1_row;
|
return field_1_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRowRelative()
|
public final boolean isRowRelative() {
|
||||||
{
|
|
||||||
return rowRelative.isSet(field_2_col);
|
return rowRelative.isSet(field_2_col);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRowRelative(boolean rel) {
|
public final void setRowRelative(boolean rel) {
|
||||||
field_2_col=rowRelative.setBoolean(field_2_col,rel);
|
field_2_col=rowRelative.setBoolean(field_2_col,rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isColRelative()
|
public final boolean isColRelative() {
|
||||||
{
|
|
||||||
return colRelative.isSet(field_2_col);
|
return colRelative.isSet(field_2_col);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColRelative(boolean rel) {
|
public final void setColRelative(boolean rel) {
|
||||||
field_2_col=colRelative.setBoolean(field_2_col,rel);
|
field_2_col=colRelative.setBoolean(field_2_col,rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColumnRaw(int col)
|
public final void setColumnRawX(int col) { // TODO
|
||||||
{
|
|
||||||
field_2_col = col;
|
field_2_col = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumnRaw()
|
public int getColumnRawX() { // TODO
|
||||||
{
|
|
||||||
return field_2_col;
|
return field_2_col;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColumn(int col)
|
public final void setColumn(int col) {
|
||||||
{
|
if(col < 0 || col >= 0x100) {
|
||||||
if(col < 0 || col > 0x100) {
|
|
||||||
throw new IllegalArgumentException("Specified colIx (" + col + ") is out of range");
|
throw new IllegalArgumentException("Specified colIx (" + col + ") is out of range");
|
||||||
}
|
}
|
||||||
field_2_col = column.setValue(field_2_col, col);
|
field_2_col = column.setValue(field_2_col, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumn() {
|
public final int getColumn() {
|
||||||
return column.getValue(field_2_col);
|
return column.getValue(field_2_col);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize()
|
public final int getSize() {
|
||||||
{
|
|
||||||
return SIZE;
|
return SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
public final String toFormulaString(HSSFWorkbook book) {
|
||||||
{
|
|
||||||
//TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
|
//TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
|
||||||
return (new CellReference(getRowAsInt(),getColumn(),!isRowRelative(),!isColRelative())).formatAsString();
|
return (new CellReference(getRowAsInt(),getColumn(),!isRowRelative(),!isColRelative())).formatAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getDefaultOperandClass() {
|
public final byte getDefaultOperandClass() {
|
||||||
return Ptg.CLASS_REF;
|
return Ptg.CLASS_REF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
ReferencePtg ptg = new ReferencePtg();
|
|
||||||
ptg.field_1_row = field_1_row;
|
|
||||||
ptg.field_2_col = field_2_col;
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,57 +0,0 @@
|
|||||||
/* ====================================================================
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
contributor license agreements. See the NOTICE file distributed with
|
|
||||||
this work for additional information regarding copyright ownership.
|
|
||||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
(the "License"); you may not use this file except in compliance with
|
|
||||||
the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
==================================================================== */
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RefVPtg
|
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
|
||||||
*/
|
|
||||||
public final class RefVPtg extends ReferencePtg {
|
|
||||||
public final static byte sid = 0x44;
|
|
||||||
|
|
||||||
protected RefVPtg() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RefVPtg(int row, int column, boolean isRowRelative, boolean isColumnRelative) {
|
|
||||||
super(row, column, isRowRelative, isColumnRelative);
|
|
||||||
setClass(CLASS_VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Creates new ValueReferencePtg */
|
|
||||||
|
|
||||||
public RefVPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
super(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRefPtgName() {
|
|
||||||
return "RefVPtg";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
RefVPtg ptg = new RefVPtg();
|
|
||||||
ptg.setRow(getRow());
|
|
||||||
ptg.setColumnRaw(getColumnRaw());
|
|
||||||
ptg.setClass(ptgClass);
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,5 +27,4 @@ abstract class ScalarConstantPtg extends Ptg {
|
|||||||
public final byte getDefaultOperandClass() {
|
public final byte getDefaultOperandClass() {
|
||||||
return Ptg.CLASS_VALUE;
|
return Ptg.CLASS_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,15 +42,11 @@ public final class StringPtg extends ScalarConstantPtg {
|
|||||||
* NOTE: OO doc says 16bit length, but BiffViewer says 8 Book says something
|
* NOTE: OO doc says 16bit length, but BiffViewer says 8 Book says something
|
||||||
* totally different, so don't look there!
|
* totally different, so don't look there!
|
||||||
*/
|
*/
|
||||||
private int field_1_length;
|
private final int field_1_length;
|
||||||
private byte field_2_options;
|
private final byte field_2_options;
|
||||||
private String field_3_string;
|
private final String field_3_string;
|
||||||
|
|
||||||
private StringPtg() {
|
/** Create a StringPtg from a stream */
|
||||||
// Required for clone methods
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create a StringPtg from a byte array read from disk */
|
|
||||||
public StringPtg(RecordInputStream in) {
|
public StringPtg(RecordInputStream in) {
|
||||||
field_1_length = in.readUByte();
|
field_1_length = in.readUByte();
|
||||||
field_2_options = in.readByte();
|
field_2_options = in.readByte();
|
||||||
@ -76,9 +72,7 @@ public final class StringPtg extends ScalarConstantPtg {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"String literals in formulas can't be bigger than 255 characters ASCII");
|
"String literals in formulas can't be bigger than 255 characters ASCII");
|
||||||
}
|
}
|
||||||
field_2_options = 0;
|
field_2_options = (byte) fHighByte.setBoolean(0, StringUtil.hasMultibyte(value));
|
||||||
field_2_options = (byte) fHighByte.setBoolean(field_2_options, StringUtil
|
|
||||||
.hasMultibyte(value));
|
|
||||||
field_3_string = value;
|
field_3_string = value;
|
||||||
field_1_length = value.length(); // for the moment, we support only ASCII strings in formulas we create
|
field_1_length = value.length(); // for the moment, we support only ASCII strings in formulas we create
|
||||||
}
|
}
|
||||||
@ -124,14 +118,6 @@ public final class StringPtg extends ScalarConstantPtg {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
StringPtg ptg = new StringPtg();
|
|
||||||
ptg.field_1_length = field_1_length;
|
|
||||||
ptg.field_2_options = field_2_options;
|
|
||||||
ptg.field_3_string = field_3_string;
|
|
||||||
return ptg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer(64);
|
StringBuffer sb = new StringBuffer(64);
|
||||||
sb.append(getClass().getName()).append(" [");
|
sb.append(getClass().getName()).append(" [");
|
||||||
|
@ -17,55 +17,28 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author andy
|
* @author andy
|
||||||
* @author Jason Height (jheight at chariot dot net dot au)
|
* @author Jason Height (jheight at chariot dot net dot au)
|
||||||
*/
|
*/
|
||||||
public final class SubtractPtg extends ValueOperatorPtg {
|
public final class SubtractPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x04;
|
public final static byte sid = 0x04;
|
||||||
|
|
||||||
public SubtractPtg()
|
public static final ValueOperatorPtg instance = new SubtractPtg();
|
||||||
{
|
|
||||||
|
private SubtractPtg() {
|
||||||
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubtractPtg(RecordInputStream in)
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeBytes(byte [] array, int offset)
|
public int getNumberOfOperands() {
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return "-";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
@ -74,8 +47,4 @@ public final class SubtractPtg extends ValueOperatorPtg {
|
|||||||
buffer.append(operands[ 1 ]);
|
buffer.append(operands[ 1 ]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new SubtractPtg();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,62 +17,30 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unary Plus operator
|
* Unary Plus operator
|
||||||
* does not have any effect on the operand
|
* does not have any effect on the operand
|
||||||
* @author Avik Sengupta
|
* @author Avik Sengupta
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class UnaryMinusPtg extends ValueOperatorPtg {
|
public final class UnaryMinusPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x13;
|
public final static byte sid = 0x13;
|
||||||
|
|
||||||
private final static String MINUS = "-";
|
private final static String MINUS = "-";
|
||||||
|
|
||||||
/** Creates new AddPtg */
|
public static final ValueOperatorPtg instance = new UnaryMinusPtg();
|
||||||
|
|
||||||
public UnaryMinusPtg()
|
private UnaryMinusPtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnaryMinusPtg(RecordInputStream in)
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumberOfOperands() {
|
||||||
public void writeBytes(byte [] array, int offset)
|
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return this.TYPE_UNARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Implementation of method from Ptg */
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return "+";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** implementation of method from OperationsPtg*/
|
/** implementation of method from OperationsPtg*/
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
@ -80,9 +48,4 @@ public final class UnaryMinusPtg extends ValueOperatorPtg {
|
|||||||
buffer.append(operands[ 0]);
|
buffer.append(operands[ 0]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new UnaryPlusPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,62 +17,30 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unary Plus operator
|
* Unary Plus operator
|
||||||
* does not have any effect on the operand
|
* does not have any effect on the operand
|
||||||
* @author Avik Sengupta
|
* @author Avik Sengupta
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class UnaryPlusPtg extends ValueOperatorPtg {
|
public final class UnaryPlusPtg extends ValueOperatorPtg {
|
||||||
public final static int SIZE = 1;
|
|
||||||
public final static byte sid = 0x12;
|
public final static byte sid = 0x12;
|
||||||
|
|
||||||
private final static String ADD = "+";
|
private final static String ADD = "+";
|
||||||
|
|
||||||
/** Creates new AddPtg */
|
public static final ValueOperatorPtg instance = new UnaryPlusPtg();
|
||||||
|
|
||||||
public UnaryPlusPtg()
|
private UnaryPlusPtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnaryPlusPtg(RecordInputStream in)
|
protected byte getSid() {
|
||||||
{
|
return sid;
|
||||||
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumberOfOperands() {
|
||||||
public void writeBytes(byte [] array, int offset)
|
|
||||||
{
|
|
||||||
array[ offset + 0 ] = sid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize()
|
|
||||||
{
|
|
||||||
return SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return this.TYPE_UNARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfOperands()
|
|
||||||
{
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Implementation of method from Ptg */
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
|
||||||
{
|
|
||||||
return "+";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** implementation of method from OperationsPtg*/
|
/** implementation of method from OperationsPtg*/
|
||||||
public String toFormulaString(String[] operands) {
|
public String toFormulaString(String[] operands) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
@ -80,9 +48,4 @@ public final class UnaryPlusPtg extends ValueOperatorPtg {
|
|||||||
buffer.append(operands[ 0]);
|
buffer.append(operands[ 0]);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
|
||||||
return new UnaryPlusPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.hssf.record.RecordInputStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Glen Stampoultzis (glens at apache.org)
|
* @author Glen Stampoultzis (glens at apache.org)
|
||||||
@ -26,14 +25,10 @@ import org.apache.poi.hssf.record.RecordInputStream;
|
|||||||
public final class UnionPtg extends OperationPtg {
|
public final class UnionPtg extends OperationPtg {
|
||||||
public final static byte sid = 0x10;
|
public final static byte sid = 0x10;
|
||||||
|
|
||||||
|
public static final OperationPtg instance = new UnionPtg();
|
||||||
|
|
||||||
public UnionPtg()
|
private UnionPtg() {
|
||||||
{
|
// enforce singleton
|
||||||
}
|
|
||||||
|
|
||||||
public UnionPtg(RecordInputStream in)
|
|
||||||
{
|
|
||||||
// doesn't need anything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isBaseToken() {
|
public final boolean isBaseToken() {
|
||||||
@ -50,17 +45,6 @@ public final class UnionPtg extends OperationPtg {
|
|||||||
array[ offset + 0 ] = sid;
|
array[ offset + 0 ] = sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone()
|
|
||||||
{
|
|
||||||
return new UnionPtg();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getType()
|
|
||||||
{
|
|
||||||
return TYPE_BINARY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Implementation of method from Ptg */
|
|
||||||
public String toFormulaString(HSSFWorkbook book)
|
public String toFormulaString(HSSFWorkbook book)
|
||||||
{
|
{
|
||||||
return ",";
|
return ",";
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common superclass of all value operators.
|
* Common superclass of all value operators.
|
||||||
* Subclasses include all unary and binary operators except for the reference operators (IntersectionPtg, RangePtg, UnionPtg)
|
* Subclasses include all unary and binary operators except for the reference operators (IntersectionPtg, RangePtg, UnionPtg)
|
||||||
@ -26,12 +28,27 @@ package org.apache.poi.hssf.record.formula;
|
|||||||
public abstract class ValueOperatorPtg extends OperationPtg {
|
public abstract class ValueOperatorPtg extends OperationPtg {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All Operator <tt>Ptg</tt>s are base tokens (i.e. are not RVA classifed)
|
* All Operator <tt>Ptg</tt>s are base tokens (i.e. are not RVA classified)
|
||||||
*/
|
*/
|
||||||
public final boolean isBaseToken() {
|
public final boolean isBaseToken() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final byte getDefaultOperandClass() {
|
public final byte getDefaultOperandClass() {
|
||||||
return Ptg.CLASS_VALUE;
|
return Ptg.CLASS_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void writeBytes(byte[] array, int offset) {
|
||||||
|
array[offset + 0] = getSid();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract byte getSid();
|
||||||
|
|
||||||
|
public final int getSize() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
public final String toFormulaString(HSSFWorkbook book) {
|
||||||
|
// TODO - prune this method out of the hierarchy
|
||||||
|
throw new RuntimeException("toFormulaString(String[] operands) should be used for subclasses of OperationPtgs");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula.eval;
|
package org.apache.poi.hssf.record.formula.eval;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author adeshmukh
|
* @author adeshmukh
|
||||||
@ -26,9 +26,9 @@ import org.apache.poi.hssf.record.formula.ReferencePtg;
|
|||||||
public final class Ref2DEval implements RefEval {
|
public final class Ref2DEval implements RefEval {
|
||||||
|
|
||||||
private final ValueEval value;
|
private final ValueEval value;
|
||||||
private final ReferencePtg delegate;
|
private final RefPtg delegate;
|
||||||
|
|
||||||
public Ref2DEval(ReferencePtg ptg, ValueEval ve) {
|
public Ref2DEval(RefPtg ptg, ValueEval ve) {
|
||||||
if(ve == null) {
|
if(ve == null) {
|
||||||
throw new IllegalArgumentException("ve must not be null");
|
throw new IllegalArgumentException("ve must not be null");
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ import org.apache.poi.hssf.record.formula.OperationPtg;
|
|||||||
import org.apache.poi.hssf.record.formula.ParenthesisPtg;
|
import org.apache.poi.hssf.record.formula.ParenthesisPtg;
|
||||||
import org.apache.poi.hssf.record.formula.Ptg;
|
import org.apache.poi.hssf.record.formula.Ptg;
|
||||||
import org.apache.poi.hssf.record.formula.Ref3DPtg;
|
import org.apache.poi.hssf.record.formula.Ref3DPtg;
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
import org.apache.poi.hssf.record.formula.StringPtg;
|
import org.apache.poi.hssf.record.formula.StringPtg;
|
||||||
import org.apache.poi.hssf.record.formula.UnionPtg;
|
import org.apache.poi.hssf.record.formula.UnionPtg;
|
||||||
import org.apache.poi.hssf.record.formula.UnknownPtg;
|
import org.apache.poi.hssf.record.formula.UnknownPtg;
|
||||||
@ -386,8 +386,8 @@ public class HSSFFormulaEvaluator {
|
|||||||
Eval opresult = invokeOperation(operation, ops, srcRowNum, srcColNum, workbook, sheet);
|
Eval opresult = invokeOperation(operation, ops, srcRowNum, srcColNum, workbook, sheet);
|
||||||
stack.push(opresult);
|
stack.push(opresult);
|
||||||
}
|
}
|
||||||
else if (ptg instanceof ReferencePtg) {
|
else if (ptg instanceof RefPtg) {
|
||||||
ReferencePtg refPtg = (ReferencePtg) ptg;
|
RefPtg refPtg = (RefPtg) ptg;
|
||||||
int colIx = refPtg.getColumn();
|
int colIx = refPtg.getColumn();
|
||||||
int rowIx = refPtg.getRow();
|
int rowIx = refPtg.getRow();
|
||||||
HSSFRow row = sheet.getRow(rowIx);
|
HSSFRow row = sheet.getRow(rowIx);
|
||||||
@ -549,7 +549,7 @@ public class HSSFFormulaEvaluator {
|
|||||||
Constructor constructor = clazz.getConstructor(AREA3D_CONSTRUCTOR_CLASS_ARRAY);
|
Constructor constructor = clazz.getConstructor(AREA3D_CONSTRUCTOR_CLASS_ARRAY);
|
||||||
retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
|
retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
|
||||||
}
|
}
|
||||||
else if (ptg instanceof ReferencePtg) {
|
else if (ptg instanceof RefPtg) {
|
||||||
Constructor constructor = clazz.getConstructor(REFERENCE_CONSTRUCTOR_CLASS_ARRAY);
|
Constructor constructor = clazz.getConstructor(REFERENCE_CONSTRUCTOR_CLASS_ARRAY);
|
||||||
retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
|
retval = (OperationEval) constructor.newInstance(new Ptg[] { ptg });
|
||||||
}
|
}
|
||||||
@ -607,7 +607,7 @@ public class HSSFFormulaEvaluator {
|
|||||||
* Creates a Ref2DEval for ReferencePtg.
|
* Creates a Ref2DEval for ReferencePtg.
|
||||||
* Non existent cells are treated as RefEvals containing BlankEval.
|
* Non existent cells are treated as RefEvals containing BlankEval.
|
||||||
*/
|
*/
|
||||||
private static Ref2DEval createRef2DEval(ReferencePtg ptg, HSSFCell cell,
|
private static Ref2DEval createRef2DEval(RefPtg ptg, HSSFCell cell,
|
||||||
HSSFRow row, HSSFSheet sheet, HSSFWorkbook workbook) {
|
HSSFRow row, HSSFSheet sheet, HSSFWorkbook workbook) {
|
||||||
if (cell == null) {
|
if (cell == null) {
|
||||||
return new Ref2DEval(ptg, BlankEval.INSTANCE);
|
return new Ref2DEval(ptg, BlankEval.INSTANCE);
|
||||||
|
@ -37,7 +37,7 @@ import org.apache.poi.hssf.model.Sheet;
|
|||||||
import org.apache.poi.hssf.model.Workbook;
|
import org.apache.poi.hssf.model.Workbook;
|
||||||
import org.apache.poi.hssf.record.*;
|
import org.apache.poi.hssf.record.*;
|
||||||
import org.apache.poi.hssf.record.formula.Ptg;
|
import org.apache.poi.hssf.record.formula.Ptg;
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
import org.apache.poi.hssf.util.HSSFCellRangeAddress;
|
import org.apache.poi.hssf.util.HSSFCellRangeAddress;
|
||||||
import org.apache.poi.hssf.util.HSSFDataValidation;
|
import org.apache.poi.hssf.util.HSSFDataValidation;
|
||||||
import org.apache.poi.hssf.util.PaneInformation;
|
import org.apache.poi.hssf.util.PaneInformation;
|
||||||
@ -1304,8 +1304,8 @@ public final class HSSFSheet {
|
|||||||
Ptg[] ptgs = fp.getRPNPtg();
|
Ptg[] ptgs = fp.getRPNPtg();
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
for(int i=0; i<ptgs.length; i++) {
|
for(int i=0; i<ptgs.length; i++) {
|
||||||
if(ptgs[i] instanceof ReferencePtg) {
|
if(ptgs[i] instanceof RefPtg) {
|
||||||
ReferencePtg rptg = (ReferencePtg)ptgs[i];
|
RefPtg rptg = (RefPtg)ptgs[i];
|
||||||
if(startRow <= rptg.getRowAsInt() &&
|
if(startRow <= rptg.getRowAsInt() &&
|
||||||
rptg.getRowAsInt() <= endRow) {
|
rptg.getRowAsInt() <= endRow) {
|
||||||
// References a row that moved
|
// References a row that moved
|
||||||
|
@ -909,9 +909,7 @@ public class HSSFWorkbook extends POIDocument
|
|||||||
|
|
||||||
if (settingRowAndColumn)
|
if (settingRowAndColumn)
|
||||||
{
|
{
|
||||||
MemFuncPtg memFuncPtg = new MemFuncPtg();
|
ptgs.add(new MemFuncPtg(23)); // TODO - where did constant '23' come from?
|
||||||
memFuncPtg.setLenRefSubexpression(23);
|
|
||||||
ptgs.add(memFuncPtg);
|
|
||||||
}
|
}
|
||||||
if (startColumn >= 0)
|
if (startColumn >= 0)
|
||||||
{
|
{
|
||||||
@ -935,8 +933,7 @@ public class HSSFWorkbook extends POIDocument
|
|||||||
}
|
}
|
||||||
if (settingRowAndColumn)
|
if (settingRowAndColumn)
|
||||||
{
|
{
|
||||||
UnionPtg unionPtg = new UnionPtg();
|
ptgs.add(UnionPtg.instance);
|
||||||
ptgs.add(unionPtg);
|
|
||||||
}
|
}
|
||||||
nameRecord.setNameDefinition(ptgs);
|
nameRecord.setNameDefinition(ptgs);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ import org.apache.poi.hssf.record.formula.NumberPtg;
|
|||||||
import org.apache.poi.hssf.record.formula.PercentPtg;
|
import org.apache.poi.hssf.record.formula.PercentPtg;
|
||||||
import org.apache.poi.hssf.record.formula.PowerPtg;
|
import org.apache.poi.hssf.record.formula.PowerPtg;
|
||||||
import org.apache.poi.hssf.record.formula.Ptg;
|
import org.apache.poi.hssf.record.formula.Ptg;
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
import org.apache.poi.hssf.record.formula.StringPtg;
|
import org.apache.poi.hssf.record.formula.StringPtg;
|
||||||
import org.apache.poi.hssf.record.formula.SubtractPtg;
|
import org.apache.poi.hssf.record.formula.SubtractPtg;
|
||||||
import org.apache.poi.hssf.record.formula.UnaryMinusPtg;
|
import org.apache.poi.hssf.record.formula.UnaryMinusPtg;
|
||||||
@ -165,14 +165,14 @@ public final class TestFormulaParser extends TestCase {
|
|||||||
public void testUnaryMinus() {
|
public void testUnaryMinus() {
|
||||||
Ptg[] ptgs = parseFormula("-A1");
|
Ptg[] ptgs = parseFormula("-A1");
|
||||||
assertEquals(2, ptgs.length);
|
assertEquals(2, ptgs.length);
|
||||||
assertTrue("first ptg is reference",ptgs[0] instanceof ReferencePtg);
|
assertTrue("first ptg is reference",ptgs[0] instanceof RefPtg);
|
||||||
assertTrue("second ptg is Minus",ptgs[1] instanceof UnaryMinusPtg);
|
assertTrue("second ptg is Minus",ptgs[1] instanceof UnaryMinusPtg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnaryPlus() {
|
public void testUnaryPlus() {
|
||||||
Ptg[] ptgs = parseFormula("+A1");
|
Ptg[] ptgs = parseFormula("+A1");
|
||||||
assertEquals(2, ptgs.length);
|
assertEquals(2, ptgs.length);
|
||||||
assertTrue("first ptg is reference",ptgs[0] instanceof ReferencePtg);
|
assertTrue("first ptg is reference",ptgs[0] instanceof RefPtg);
|
||||||
assertTrue("second ptg is Plus",ptgs[1] instanceof UnaryPlusPtg);
|
assertTrue("second ptg is Plus",ptgs[1] instanceof UnaryPlusPtg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,11 +540,11 @@ public final class TestFormulaParser extends TestCase {
|
|||||||
Class[] expClss;
|
Class[] expClss;
|
||||||
|
|
||||||
expClss = new Class[] {
|
expClss = new Class[] {
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
AttrPtg.class, // tAttrIf
|
AttrPtg.class, // tAttrIf
|
||||||
MissingArgPtg.class,
|
MissingArgPtg.class,
|
||||||
AttrPtg.class, // tAttrSkip
|
AttrPtg.class, // tAttrSkip
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
AttrPtg.class, // tAttrSkip
|
AttrPtg.class, // tAttrSkip
|
||||||
FuncVarPtg.class,
|
FuncVarPtg.class,
|
||||||
};
|
};
|
||||||
@ -696,7 +696,7 @@ public final class TestFormulaParser extends TestCase {
|
|||||||
// FormulaParser strips spaces anyway
|
// FormulaParser strips spaces anyway
|
||||||
assertEquals("4", formulaString);
|
assertEquals("4", formulaString);
|
||||||
|
|
||||||
ptgs = new Ptg[] { new IntPtg(3), spacePtg, new IntPtg(4), spacePtg, new AddPtg()};
|
ptgs = new Ptg[] { new IntPtg(3), spacePtg, new IntPtg(4), spacePtg, AddPtg.instance, };
|
||||||
formulaString = FormulaParser.toFormulaString(null, ptgs);
|
formulaString = FormulaParser.toFormulaString(null, ptgs);
|
||||||
assertEquals("3+4", formulaString);
|
assertEquals("3+4", formulaString);
|
||||||
}
|
}
|
||||||
@ -710,7 +710,7 @@ public final class TestFormulaParser extends TestCase {
|
|||||||
Ptg[] ptgs = {
|
Ptg[] ptgs = {
|
||||||
// Excel would probably have put tMissArg here
|
// Excel would probably have put tMissArg here
|
||||||
new IntPtg(1),
|
new IntPtg(1),
|
||||||
new DividePtg(),
|
DividePtg.instance,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
FormulaParser.toFormulaString(null, ptgs);
|
FormulaParser.toFormulaString(null, ptgs);
|
||||||
|
@ -31,7 +31,7 @@ import org.apache.poi.hssf.record.formula.LessThanPtg;
|
|||||||
import org.apache.poi.hssf.record.formula.MultiplyPtg;
|
import org.apache.poi.hssf.record.formula.MultiplyPtg;
|
||||||
import org.apache.poi.hssf.record.formula.NotEqualPtg;
|
import org.apache.poi.hssf.record.formula.NotEqualPtg;
|
||||||
import org.apache.poi.hssf.record.formula.Ptg;
|
import org.apache.poi.hssf.record.formula.Ptg;
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
import org.apache.poi.hssf.record.formula.StringPtg;
|
import org.apache.poi.hssf.record.formula.StringPtg;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ public final class TestFormulaParserIf extends TestCase {
|
|||||||
Class[] expClss;
|
Class[] expClss;
|
||||||
|
|
||||||
expClss = new Class[] {
|
expClss = new Class[] {
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
AttrPtg.class, // tAttrIf
|
AttrPtg.class, // tAttrIf
|
||||||
IntPtg.class,
|
IntPtg.class,
|
||||||
AttrPtg.class, // tAttrSkip
|
AttrPtg.class, // tAttrSkip
|
||||||
@ -82,9 +82,9 @@ public final class TestFormulaParserIf extends TestCase {
|
|||||||
Class[] expClss;
|
Class[] expClss;
|
||||||
|
|
||||||
expClss = new Class[] {
|
expClss = new Class[] {
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
AttrPtg.class, // tAttrIf
|
AttrPtg.class, // tAttrIf
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
AttrPtg.class, // tAttrSkip
|
AttrPtg.class, // tAttrSkip
|
||||||
FuncVarPtg.class,
|
FuncVarPtg.class,
|
||||||
};
|
};
|
||||||
@ -100,20 +100,20 @@ public final class TestFormulaParserIf extends TestCase {
|
|||||||
Class[] expClss;
|
Class[] expClss;
|
||||||
|
|
||||||
expClss = new Class[] {
|
expClss = new Class[] {
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
AttrPtg.class, // tAttrIf
|
AttrPtg.class, // tAttrIf
|
||||||
|
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
IntPtg.class,
|
IntPtg.class,
|
||||||
MultiplyPtg.class,
|
MultiplyPtg.class,
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
IntPtg.class,
|
IntPtg.class,
|
||||||
AddPtg.class,
|
AddPtg.class,
|
||||||
FuncPtg.class,
|
FuncPtg.class,
|
||||||
AttrPtg.class, // tAttrSkip
|
AttrPtg.class, // tAttrSkip
|
||||||
|
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
FuncPtg.class,
|
FuncPtg.class,
|
||||||
|
|
||||||
AttrPtg.class, // tAttrSkip
|
AttrPtg.class, // tAttrSkip
|
||||||
@ -133,9 +133,9 @@ public final class TestFormulaParserIf extends TestCase {
|
|||||||
|
|
||||||
expClss = new Class[] {
|
expClss = new Class[] {
|
||||||
|
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
AttrPtg.class, // A tAttrIf
|
AttrPtg.class, // A tAttrIf
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
AttrPtg.class, // B tAttrIf
|
AttrPtg.class, // B tAttrIf
|
||||||
IntPtg.class,
|
IntPtg.class,
|
||||||
AttrPtg.class, // B tAttrSkip
|
AttrPtg.class, // B tAttrSkip
|
||||||
@ -143,7 +143,7 @@ public final class TestFormulaParserIf extends TestCase {
|
|||||||
AttrPtg.class, // B tAttrSkip
|
AttrPtg.class, // B tAttrSkip
|
||||||
FuncVarPtg.class,
|
FuncVarPtg.class,
|
||||||
AttrPtg.class, // A tAttrSkip
|
AttrPtg.class, // A tAttrSkip
|
||||||
ReferencePtg.class,
|
RefPtg.class,
|
||||||
AttrPtg.class, // C tAttrIf
|
AttrPtg.class, // C tAttrIf
|
||||||
IntPtg.class,
|
IntPtg.class,
|
||||||
AttrPtg.class, // C tAttrSkip
|
AttrPtg.class, // C tAttrSkip
|
||||||
|
@ -23,7 +23,7 @@ import junit.framework.TestCase;
|
|||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.record.formula.AttrPtg;
|
import org.apache.poi.hssf.record.formula.AttrPtg;
|
||||||
import org.apache.poi.hssf.record.formula.Ptg;
|
import org.apache.poi.hssf.record.formula.Ptg;
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtgBase;
|
||||||
import org.apache.poi.hssf.usermodel.FormulaExtractor;
|
import org.apache.poi.hssf.usermodel.FormulaExtractor;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||||
@ -102,7 +102,7 @@ public final class TestRVA extends TestCase {
|
|||||||
for (int i = 0; i < nExcelTokens; i++) {
|
for (int i = 0; i < nExcelTokens; i++) {
|
||||||
Ptg poiPtg = poiPtgs[i];
|
Ptg poiPtg = poiPtgs[i];
|
||||||
Ptg excelPtg = excelPtgs[i];
|
Ptg excelPtg = excelPtgs[i];
|
||||||
if (!areTokenClassesSame(poiPtg, excelPtg)) {
|
if (excelPtg.getClass() != poiPtg.getClass()) {
|
||||||
hasMismatch = true;
|
hasMismatch = true;
|
||||||
sb.append(" mismatch token type[" + i + "] " + getShortClassName(excelPtg) + " "
|
sb.append(" mismatch token type[" + i + "] " + getShortClassName(excelPtg) + " "
|
||||||
+ getOperandClassName(excelPtg) + " - " + getShortClassName(poiPtg) + " "
|
+ getOperandClassName(excelPtg) + " - " + getShortClassName(poiPtg) + " "
|
||||||
@ -127,17 +127,6 @@ public final class TestRVA extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean areTokenClassesSame(Ptg poiPtg, Ptg excelPtg) {
|
|
||||||
if (excelPtg.getClass() == poiPtg.getClass()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (poiPtg.getClass() == ReferencePtg.class) {
|
|
||||||
// TODO - remove funny subclasses of ReferencePtg
|
|
||||||
return excelPtg instanceof ReferencePtg;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getShortClassName(Object o) {
|
private String getShortClassName(Object o) {
|
||||||
String cn = o.getClass().getName();
|
String cn = o.getClass().getName();
|
||||||
int pos = cn.lastIndexOf('.');
|
int pos = cn.lastIndexOf('.');
|
||||||
|
@ -26,7 +26,7 @@ import junit.framework.TestCase;
|
|||||||
import org.apache.poi.hssf.record.formula.AttrPtg;
|
import org.apache.poi.hssf.record.formula.AttrPtg;
|
||||||
import org.apache.poi.hssf.record.formula.FuncVarPtg;
|
import org.apache.poi.hssf.record.formula.FuncVarPtg;
|
||||||
import org.apache.poi.hssf.record.formula.IntPtg;
|
import org.apache.poi.hssf.record.formula.IntPtg;
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the serialization and deserialization of the FormulaRecord
|
* Tests the serialization and deserialization of the FormulaRecord
|
||||||
@ -130,11 +130,11 @@ public final class TestFormulaRecord extends TestCase {
|
|||||||
assertEquals(9, ptgs.size());
|
assertEquals(9, ptgs.size());
|
||||||
assertEquals(IntPtg.class, ptgs.get(0).getClass());
|
assertEquals(IntPtg.class, ptgs.get(0).getClass());
|
||||||
assertEquals(AttrPtg.class, ptgs.get(1).getClass());
|
assertEquals(AttrPtg.class, ptgs.get(1).getClass());
|
||||||
assertEquals(ReferencePtg.class, ptgs.get(2).getClass());
|
assertEquals(RefPtg.class, ptgs.get(2).getClass());
|
||||||
assertEquals(AttrPtg.class, ptgs.get(3).getClass());
|
assertEquals(AttrPtg.class, ptgs.get(3).getClass());
|
||||||
assertEquals(ReferencePtg.class, ptgs.get(4).getClass());
|
assertEquals(RefPtg.class, ptgs.get(4).getClass());
|
||||||
assertEquals(AttrPtg.class, ptgs.get(5).getClass());
|
assertEquals(AttrPtg.class, ptgs.get(5).getClass());
|
||||||
assertEquals(ReferencePtg.class, ptgs.get(6).getClass());
|
assertEquals(RefPtg.class, ptgs.get(6).getClass());
|
||||||
assertEquals(AttrPtg.class, ptgs.get(7).getClass());
|
assertEquals(AttrPtg.class, ptgs.get(7).getClass());
|
||||||
assertEquals(FuncVarPtg.class, ptgs.get(8).getClass());
|
assertEquals(FuncVarPtg.class, ptgs.get(8).getClass());
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ import junit.framework.ComparisonFailure;
|
|||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.Ptg;
|
import org.apache.poi.hssf.record.formula.Ptg;
|
||||||
import org.apache.poi.hssf.record.formula.RefAPtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Josh Micich
|
* @author Josh Micich
|
||||||
@ -68,7 +68,7 @@ public final class TestSharedFormulaRecord extends TestCase {
|
|||||||
|
|
||||||
Stack convertedFormula = SharedFormulaRecord.convertSharedFormulas(sharedFormula, 100, 200);
|
Stack convertedFormula = SharedFormulaRecord.convertSharedFormulas(sharedFormula, 100, 200);
|
||||||
|
|
||||||
RefAPtg refPtg = (RefAPtg) convertedFormula.get(1);
|
RefPtg refPtg = (RefPtg) convertedFormula.get(1);
|
||||||
assertEquals("$C101", refPtg.toFormulaString(null));
|
assertEquals("$C101", refPtg.toFormulaString(null));
|
||||||
if (refPtg.getPtgClass() == Ptg.CLASS_REF) {
|
if (refPtg.getPtgClass() == Ptg.CLASS_REF) {
|
||||||
throw new AssertionFailedError("Identified bug 45123");
|
throw new AssertionFailedError("Identified bug 45123");
|
||||||
|
@ -54,12 +54,12 @@ public final class TestArrayPtg extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testReadWriteTokenValueBytes() {
|
public void testReadWriteTokenValueBytes() {
|
||||||
|
|
||||||
ArrayPtg ptg = new ArrayPtgV(new TestcaseRecordInputStream(ArrayPtgV.sid, ENCODED_PTG_DATA));
|
ArrayPtg ptg = new ArrayPtg(new TestcaseRecordInputStream(ArrayPtg.sid, ENCODED_PTG_DATA));
|
||||||
|
|
||||||
ptg.readTokenValues(new TestcaseRecordInputStream(0, ENCODED_CONSTANT_DATA));
|
ptg.readTokenValues(new TestcaseRecordInputStream(0, ENCODED_CONSTANT_DATA));
|
||||||
assertEquals(3, ptg.getColumnCount());
|
assertEquals(3, ptg.getColumnCount());
|
||||||
assertEquals(2, ptg.getRowCount());
|
assertEquals(2, ptg.getRowCount());
|
||||||
Object[] values = ptg.token_3_arrayValues;
|
Object[] values = ptg.getTokenArrayValues();
|
||||||
assertEquals(6, values.length);
|
assertEquals(6, values.length);
|
||||||
|
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ public final class TestArrayPtg extends TestCase {
|
|||||||
* Excel stores array elements column by column. This test makes sure POI does the same.
|
* Excel stores array elements column by column. This test makes sure POI does the same.
|
||||||
*/
|
*/
|
||||||
public void testElementOrdering() {
|
public void testElementOrdering() {
|
||||||
ArrayPtg ptg = new ArrayPtgV(new TestcaseRecordInputStream(ArrayPtgV.sid, ENCODED_PTG_DATA));
|
ArrayPtg ptg = new ArrayPtg(new TestcaseRecordInputStream(ArrayPtg.sid, ENCODED_PTG_DATA));
|
||||||
ptg.readTokenValues(new TestcaseRecordInputStream(0, ENCODED_CONSTANT_DATA));
|
ptg.readTokenValues(new TestcaseRecordInputStream(0, ENCODED_CONSTANT_DATA));
|
||||||
assertEquals(3, ptg.getColumnCount());
|
assertEquals(3, ptg.getColumnCount());
|
||||||
assertEquals(2, ptg.getRowCount());
|
assertEquals(2, ptg.getRowCount());
|
||||||
|
@ -17,15 +17,19 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula;
|
package org.apache.poi.hssf.record.formula;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
|
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ReferencePtg}.
|
* Tests for {@link RefPtg}.
|
||||||
*/
|
*/
|
||||||
public final class TestReferencePtg extends TestCase {
|
public final class TestReferencePtg extends TestCase {
|
||||||
/**
|
/**
|
||||||
@ -86,5 +90,18 @@ public final class TestReferencePtg extends TestCase {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private static final byte[] tRefN_data = {
|
||||||
|
0x2C, 33, 44, 55, 66,
|
||||||
|
};
|
||||||
|
public void testReadWrite_tRefN_bug45091() {
|
||||||
|
TestcaseRecordInputStream in = new TestcaseRecordInputStream(-1, tRefN_data);
|
||||||
|
Stack ptgs = Ptg.createParsedExpressionTokens((short)tRefN_data.length, in);
|
||||||
|
byte[] outData = new byte[5];
|
||||||
|
Ptg.serializePtgStack(ptgs, outData, 0);
|
||||||
|
if (outData[0] == 0x24) {
|
||||||
|
throw new AssertionFailedError("Identified bug 45091");
|
||||||
|
}
|
||||||
|
assertTrue(Arrays.equals(tRefN_data, outData));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public final class TestPercentEval extends TestCase {
|
|||||||
arg,
|
arg,
|
||||||
};
|
};
|
||||||
|
|
||||||
PercentEval opEval = new PercentEval(new PercentPtg());
|
PercentEval opEval = new PercentEval(PercentPtg.instance);
|
||||||
double result = NumericFunctionInvoker.invoke(opEval, args, -1, (short)-1);
|
double result = NumericFunctionInvoker.invoke(opEval, args, -1, (short)-1);
|
||||||
|
|
||||||
assertEquals(expectedResult, result, 0);
|
assertEquals(expectedResult, result, 0);
|
||||||
|
@ -53,9 +53,8 @@ public final class TestUnaryPlusEval extends TestCase {
|
|||||||
areaEval,
|
areaEval,
|
||||||
};
|
};
|
||||||
|
|
||||||
double result = NumericFunctionInvoker.invoke(new UnaryPlusEval(new UnaryPlusPtg()), args, 10, (short)20);
|
double result = NumericFunctionInvoker.invoke(new UnaryPlusEval(UnaryPlusPtg.instance), args, 10, (short)20);
|
||||||
|
|
||||||
assertEquals(35, result, 0);
|
assertEquals(35, result, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
package org.apache.poi.hssf.record.formula.functions;
|
package org.apache.poi.hssf.record.formula.functions;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.AreaPtg;
|
import org.apache.poi.hssf.record.formula.AreaPtg;
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
import org.apache.poi.hssf.record.formula.eval.Area2DEval;
|
import org.apache.poi.hssf.record.formula.eval.Area2DEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
||||||
@ -58,6 +58,6 @@ final class EvalFactory {
|
|||||||
* Creates a single RefEval (with value zero)
|
* Creates a single RefEval (with value zero)
|
||||||
*/
|
*/
|
||||||
public static RefEval createRefEval(String refStr) {
|
public static RefEval createRefEval(String refStr) {
|
||||||
return new Ref2DEval(new ReferencePtg(refStr), ZERO);
|
return new Ref2DEval(new RefPtg(refStr), ZERO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ package org.apache.poi.hssf.record.formula.functions;
|
|||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.AreaPtg;
|
import org.apache.poi.hssf.record.formula.AreaPtg;
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
import org.apache.poi.hssf.record.formula.eval.Area2DEval;
|
import org.apache.poi.hssf.record.formula.eval.Area2DEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
||||||
@ -124,7 +124,7 @@ public final class TestCountFuncs extends TestCase {
|
|||||||
};
|
};
|
||||||
Area2DEval arg0 = new Area2DEval(new AreaPtg("C1:C6"), values);
|
Area2DEval arg0 = new Area2DEval(new AreaPtg("C1:C6"), values);
|
||||||
|
|
||||||
Ref2DEval criteriaArg = new Ref2DEval(new ReferencePtg("A1"), new NumberEval(25));
|
Ref2DEval criteriaArg = new Ref2DEval(new RefPtg("A1"), new NumberEval(25));
|
||||||
Eval[] args= { arg0, criteriaArg, };
|
Eval[] args= { arg0, criteriaArg, };
|
||||||
|
|
||||||
double actual = NumericFunctionInvoker.invoke(new Countif(), args);
|
double actual = NumericFunctionInvoker.invoke(new Countif(), args);
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
package org.apache.poi.hssf.record.formula.functions;
|
package org.apache.poi.hssf.record.formula.functions;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.AreaPtg;
|
import org.apache.poi.hssf.record.formula.AreaPtg;
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
import org.apache.poi.hssf.record.formula.eval.Area2DEval;
|
import org.apache.poi.hssf.record.formula.eval.Area2DEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
||||||
@ -77,7 +77,7 @@ public final class TestMid extends TestCase {
|
|||||||
|
|
||||||
// startPos is 1x1 area ref, numChars is cell ref
|
// startPos is 1x1 area ref, numChars is cell ref
|
||||||
AreaEval aeStart = new Area2DEval(new AreaPtg("A1:A1"), new ValueEval[] { new NumberEval(2), } );
|
AreaEval aeStart = new Area2DEval(new AreaPtg("A1:A1"), new ValueEval[] { new NumberEval(2), } );
|
||||||
RefEval reNumChars = new Ref2DEval(new ReferencePtg("B1"), new NumberEval(3));
|
RefEval reNumChars = new Ref2DEval(new RefPtg("B1"), new NumberEval(3));
|
||||||
confirmMid(new StringEval("galactic"), aeStart, reNumChars, "ala");
|
confirmMid(new StringEval("galactic"), aeStart, reNumChars, "ala");
|
||||||
|
|
||||||
confirmMid(new StringEval("galactic"), new NumberEval(3.1), BlankEval.INSTANCE, "");
|
confirmMid(new StringEval("galactic"), new NumberEval(3.1), BlankEval.INSTANCE, "");
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
package org.apache.poi.hssf.record.formula.functions;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
import org.apache.poi.hssf.record.formula.eval.AreaEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
import org.apache.poi.hssf.record.formula.eval.Eval;
|
||||||
@ -50,7 +50,7 @@ public final class TestSumproduct extends TestCase {
|
|||||||
|
|
||||||
public void testScalarSimple() {
|
public void testScalarSimple() {
|
||||||
|
|
||||||
RefEval refEval = new Ref2DEval(new ReferencePtg("A1"), new NumberEval(3));
|
RefEval refEval = new Ref2DEval(new RefPtg("A1"), new NumberEval(3));
|
||||||
Eval[] args = {
|
Eval[] args = {
|
||||||
refEval,
|
refEval,
|
||||||
new NumberEval(2),
|
new NumberEval(2),
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
package org.apache.poi.hssf.record.formula.functions;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.ReferencePtg;
|
import org.apache.poi.hssf.record.formula.RefPtg;
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.BoolEval;
|
import org.apache.poi.hssf.record.formula.eval.BoolEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
||||||
@ -50,7 +50,7 @@ public final class TestTFunc extends TestCase {
|
|||||||
* where cell A1 has the specified innerValue
|
* where cell A1 has the specified innerValue
|
||||||
*/
|
*/
|
||||||
private Eval invokeTWithReference(ValueEval innerValue) {
|
private Eval invokeTWithReference(ValueEval innerValue) {
|
||||||
Eval arg = new Ref2DEval(new ReferencePtg((short)1, (short)1, false, false), innerValue);
|
Eval arg = new Ref2DEval(new RefPtg((short)1, (short)1, false, false), innerValue);
|
||||||
return invokeT(arg);
|
return invokeT(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user