Package org.apache.poi.ss.formula
Class Formula
- java.lang.Object
-
- org.apache.poi.ss.formula.Formula
-
- All Implemented Interfaces:
Serializable
,GenericRecord
public class Formula extends Object implements GenericRecord, Serializable
Encapsulates an encoded formula token array.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Formula
copy()
static Formula
create(Ptg[] ptgs)
Creates a Formula object from a suppliedPtg
array.static Formula
createX(Ptg[] ptgs)
int
getEncodedSize()
int
getEncodedTokenSize()
This method is often used when the formula length does not appear immediately before the encoded token data.CellReference
getExpReference()
Gets the locator for the correspondingSharedFormulaRecord
,ArrayRecord
orTableRecord
if this formula belongs to such a grouping.Map<String,Supplier<?>>
getGenericProperties()
Ptg[]
getTokens()
static Ptg[]
getTokens(Formula formula)
Gets thePtg
array from the supplied Formula.static Ptg[]
getTokens(Formula formula, SpreadsheetVersion version)
Ptg[]
getTokens(SpreadsheetVersion version)
boolean
isSame(Formula other)
static Formula
read(int encodedTokenLen, LittleEndianInput in)
Convenience method forread(int, LittleEndianInput, int)
static Formula
read(int encodedTokenLen, LittleEndianInput in, int totalEncodedLen)
When there are no array constants present,encodedTokenLen
==totalEncodedLen
void
serialize(LittleEndianOutput out)
Writes The formula encoding is includes: ushort tokenDataLen tokenData arrayConstantData (if present)void
serializeArrayConstantData(LittleEndianOutput out)
void
serializeTokens(LittleEndianOutput out)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.poi.common.usermodel.GenericRecord
getGenericChildren, getGenericRecordType
-
-
-
-
Constructor Detail
-
Formula
public Formula(Formula other)
-
-
Method Detail
-
read
public static Formula read(int encodedTokenLen, LittleEndianInput in)
Convenience method forread(int, LittleEndianInput, int)
-
read
public static Formula read(int encodedTokenLen, LittleEndianInput in, int totalEncodedLen)
When there are no array constants present,encodedTokenLen
==totalEncodedLen
- Parameters:
encodedTokenLen
- number of bytes in the stream taken by the plain formula tokenstotalEncodedLen
- the total number of bytes in the formula (includes trailing encoding for array constants, but does not include 2 bytes for initialushort encodedTokenLen
field.- Returns:
- A new formula object as read from the stream. Possibly empty, never
null
.
-
getTokens
public Ptg[] getTokens(SpreadsheetVersion version)
-
getTokens
public Ptg[] getTokens()
-
serialize
public void serialize(LittleEndianOutput out)
Writes The formula encoding is includes:- ushort tokenDataLen
- tokenData
- arrayConstantData (if present)
-
serializeTokens
public void serializeTokens(LittleEndianOutput out)
-
serializeArrayConstantData
public void serializeArrayConstantData(LittleEndianOutput out)
-
getEncodedSize
public int getEncodedSize()
- Returns:
- total formula encoding length. The formula encoding includes:
- ushort tokenDataLen
- tokenData
- arrayConstantData (optional)
tokenDataLength
-
getEncodedTokenSize
public int getEncodedTokenSize()
This method is often used when the formula length does not appear immediately before the encoded token data.- Returns:
- the encoded length of the plain formula tokens. This does not include the leading ushort field, nor any trailing array constant data.
-
create
public static Formula create(Ptg[] ptgs)
Creates a Formula object from a suppliedPtg
array. Handlesnull
s OK.- Parameters:
ptgs
- may benull
- Returns:
- Never
null
(Possibly empty if the suppliedptgs
isnull
)
-
createX
public static Formula createX(Ptg[] ptgs)
- Parameters:
ptgs
- may benull
- Returns:
- Never
null
(Possibly empty if the suppliedptgs
isnull
)
-
getTokens
public static Ptg[] getTokens(Formula formula)
Gets thePtg
array from the supplied Formula. Handlesnull
s OK.- Parameters:
formula
- may benull
- Returns:
- possibly
null
(if the suppliedformula
isnull
)
-
getTokens
public static Ptg[] getTokens(Formula formula, SpreadsheetVersion version)
-
copy
public Formula copy()
-
getExpReference
public CellReference getExpReference()
Gets the locator for the correspondingSharedFormulaRecord
,ArrayRecord
orTableRecord
if this formula belongs to such a grouping. TheCellReference
returned by this method will match the top left corner of the range of that grouping. The return value is usually not the same as the location of the cell containing this formula.- Returns:
- the firstRow & firstColumn of an array formula or shared formula that this formula
belongs to.
null
if this formula is not part of an array or shared formula.
-
isSame
public boolean isSame(Formula other)
-
getGenericProperties
public Map<String,Supplier<?>> getGenericProperties()
- Specified by:
getGenericProperties
in interfaceGenericRecord
-
-