Top Description Fields Constructors Methods
org.apache.poi.ss.formula

public Class Formula

extends Object
implements GenericRecord
Class Inheritance
All Implemented Interfaces
org.apache.poi.common.usermodel.GenericRecord
Imports
java.util.Arrays, .Map, java.util.function.Supplier, org.apache.poi.common.usermodel.GenericRecord, org.apache.poi.ss.formula.ptg.ExpPtg, .Ptg, .TblPtg, org.apache.poi.ss.util.CellReference, org.apache.poi.util.GenericRecordUtil, .IOUtils, .LittleEndian, .LittleEndianByteArrayInputStream, .LittleEndianInput, .LittleEndianOutput

Encapsulates an encoded formula token array.

Field Summary

Modifier and TypeField and Description
private final byte[]
_byteEncoding

immutable

private final int
private static final Formula
private static final int

Constructor Summary

AccessConstructor and Description
public
private
Formula(byte[] byteEncoding, int encodedTokenLen)

Method Summary

Modifier and TypeMethod and Description
public Formula
copy()

public static Formula

Returns:

Never null (Possibly empty if the supplied ptgs is null)
create
(Ptg[]
may be null
ptgs
)

Creates a Formula object from a supplied Ptg array.

public int

Returns:

total formula encoding length. The formula encoding includes:
  • ushort tokenDataLen
  • tokenData
  • arrayConstantData (optional)
Note - this value is different to tokenDataLength
getEncodedSize
()

public int

Returns:

the encoded length of the plain formula tokens. This does not include the leading ushort field, nor any trailing array constant data.
getEncodedTokenSize
()

This method is often used when the formula length does not appear immediately before the encoded token data.

public CellReference

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.
getExpReference
()

Gets the locator for the corresponding org.apache.poi.hssf.record.SharedFormulaRecord, org.apache.poi.hssf.record.ArrayRecord or org.apache.poi.hssf.record.TableRecord if this formula belongs to such a grouping.

public Map<String, Supplier<?>>
public Ptg[]
public static Ptg[]

Returns:

possibly null (if the supplied formula is null)
getTokens
(Formula
may be null
formula
)

Gets the Ptg array from the supplied Formula.

public boolean
isSame(Formula other)

public static Formula
read(int encodedTokenLen, LittleEndianInput in)

Convenience method for read(int, LittleEndianInput, int)

public static Formula

Returns:

A new formula object as read from the stream. Possibly empty, never null.
read
(int
number of bytes in the stream taken by the plain formula tokens
encodedTokenLen
,
LittleEndianInput in, int
the total number of bytes in the formula (includes trailing encoding for array constants, but does not include 2 bytes for initial ushort encodedTokenLen field.
totalEncodedLen
)

When there are no array constants present, encodedTokenLen==totalEncodedLen

public void
serialize(LittleEndianOutput out)

Writes The formula encoding is includes:

  • ushort tokenDataLen
  • tokenData
  • arrayConstantData (if present)
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_byteEncodingback to summary
private final byte[] _byteEncoding

immutable

_encodedTokenLenback to summary
private final int _encodedTokenLen
EMPTYback to summary
private static final Formula EMPTY
MAX_ENCODED_LENback to summary
private static final int MAX_ENCODED_LEN

Constructor Detail

Formulaback to summary
public Formula(Formula other)
Formulaback to summary
private Formula(byte[] byteEncoding, int encodedTokenLen)

Method Detail

copyback to summary
public Formula copy()
createback to summary
public static Formula create(Ptg[] ptgs)

Creates a Formula object from a supplied Ptg array. Handles nulls OK.

Parameters
ptgs:Ptg[]

may be null

Returns:Formula

Never null (Possibly empty if the supplied ptgs is null)

getEncodedSizeback to summary
public int getEncodedSize()
Returns:int

total formula encoding length. The formula encoding includes:

  • ushort tokenDataLen
  • tokenData
  • arrayConstantData (optional)
Note - this value is different to tokenDataLength
getEncodedTokenSizeback to summary
public int getEncodedTokenSize()

This method is often used when the formula length does not appear immediately before the encoded token data.

Returns:int

the encoded length of the plain formula tokens. This does not include the leading ushort field, nor any trailing array constant data.

getExpReferenceback to summary
public CellReference getExpReference()

Gets the locator for the corresponding org.apache.poi.hssf.record.SharedFormulaRecord, org.apache.poi.hssf.record.ArrayRecord or org.apache.poi.hssf.record.TableRecord if this formula belongs to such a grouping. The CellReference 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:CellReference

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.

getGenericPropertiesback to summary
public Map<String, Supplier<?>> getGenericProperties()

Implements org.apache.poi.common.usermodel.GenericRecord.getGenericProperties.

Annotations
@Override
getTokensback to summary
public Ptg[] getTokens()
getTokensback to summary
public static Ptg[] getTokens(Formula formula)

Gets the Ptg array from the supplied Formula. Handles nulls OK.

Parameters
formula:Formula

may be null

Returns:Ptg[]

possibly null (if the supplied formula is null)

isSameback to summary
public boolean isSame(Formula other)
readback to summary
public static Formula read(int encodedTokenLen, LittleEndianInput in)

Convenience method for read(int, LittleEndianInput, int)

readback to summary
public static Formula read(int encodedTokenLen, LittleEndianInput in, int totalEncodedLen)

When there are no array constants present, encodedTokenLen==totalEncodedLen

Parameters
encodedTokenLen:int

number of bytes in the stream taken by the plain formula tokens

totalEncodedLen:int

the total number of bytes in the formula (includes trailing encoding for array constants, but does not include 2 bytes for initial ushort encodedTokenLen field.

Returns:Formula

A new formula object as read from the stream. Possibly empty, never null.

serializeback to summary
public void serialize(LittleEndianOutput out)

Writes The formula encoding is includes:

  • ushort tokenDataLen
  • tokenData
  • arrayConstantData (if present)
serializeArrayConstantDataback to summary
public void serializeArrayConstantData(LittleEndianOutput out)
serializeTokensback to summary
public void serializeTokens(LittleEndianOutput out)