Top Description Inners Fields Constructors Methods
org.apache.poi.ss.format

public Class CellFormatPart

extends Object
Class Inheritance
Annotations
@SuppressWarnings:RegExpRepeatedSpace
Imports
org.apache.logging.log4j.LogManager, .Logger, org.apache.poi.hssf.util.HSSFColor, org.apache.poi.util.CodepointsUtil, .LocaleUtil, javax.swing.*, java.awt.*, java.util.*, java.util.regex.Matcher, .Pattern

Objects of this class represent a single part of a cell format expression. Each cell can have up to four of these for positive, zero, negative, and text values.

Each format part can contain a color, a condition, and will always contain a format specification. For example "[Red][>=10]#" has a color ([Red]), a condition (>=10) and a format specification (#).

This class also contains patterns for matching the subparts of format specification. These are used internally, but are made public in case other code has use for them.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface

Field Summary

Modifier and TypeField and Description
private final Color
public static final int
COLOR_GROUP

Within FORMAT_PAT, the group number for the matched color.

public static final Pattern
COLOR_PAT

Pattern for the color part of a cell format part.

private final CellFormatCondition
public static final int
CONDITION_OPERATOR_GROUP

Within FORMAT_PAT, the group number for the operator in the condition.

public static final Pattern
CONDITION_PAT

Pattern for the condition part of a cell format part.

public static final int
CONDITION_VALUE_GROUP

Within FORMAT_PAT, the group number for the value in the condition.

public static final Pattern
CURRENCY_PAT

Pattern for the currency symbol part of a cell format part

private final CellFormatter
public static final Pattern
FORMAT_PAT

Pattern for an entire cell single part.

private static final Logger
pack-priv static final Map<String, Color>
public static final int
SPECIFICATION_GROUP

Within FORMAT_PAT, the group number for the format specification.

public static final Pattern
SPECIFICATION_PAT

Pattern for the format specification part of a cell format part.

private final CellFormatType

Constructor Summary

AccessConstructor and Description
public
CellFormatPart(String
The string to parse.
desc
)

Create an object to represent a format part.

public
CellFormatPart(Locale
The locale to use.
locale
,
String
The string to parse.
desc
)

Create an object to represent a format part.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this format part applies to the given value.
applies
(Object
The value to evaluate.
valueObject
)

Returns true if this format part applies to the given value.

public CellFormatResult

Returns:

A CellFormatResult object containing the results of applying the format to the value.
apply
(Object
The value to apply this format part to.
value
)

Apply this format part to the given value.

public CellFormatResult

Returns:

true if the
apply
(JLabel
The label
label
,
Object
The value to apply this format part to.
value
)

Apply this format part to the given value, applying the result to the given label.

pack-priv static String

Returns:

The character repeated three times.
expandChar
(String
The character to be repeated is the second character in this string.
part
)

Expands a character.

private static int

Returns:

The matching group number.
findGroup
(Pattern
The pattern to use.
pat
,
String
The string to match against the pattern.
str
,
String
The marker value to find the group of.
marker
)

Returns the number of the first group that is the same as the marker string.

private CellFormatType

Returns:

The type of format.
formatType
(String
The format specification
fdesc
)

Returns the type of format.

private CellFormatType

Returns:

The CellFormatType.
getCellFormatType
(Matcher
The matcher for the format part.
matcher
)

Returns the CellFormatType object implied by the format specification for the format part.

pack-priv CellFormatType

Returns:

The CellFormatType.
getCellFormatType
()

Returns the CellFormatType object implied by the format specification for the format part.

private static Color

Returns:

The color specification or null.
getColor
(Matcher
The matcher for the format part.
m
)

Returns the color specification from the matcher, or null if there is none.

private CellFormatCondition

Returns:

The condition specification or null.
getCondition
(Matcher
The matcher for the format part.
m
)

Returns the condition specification from the matcher, or null if there is none.

private CellFormatter

Returns:

The formatter.
getFormatter
(Locale locale, Matcher
The matcher for the format part.
matcher
)

Returns the formatter object implied by the format specification for the format part.

public static String

Returns:

The group or "".
group
(Matcher
The matcher.
m
,
int
The group number.
g
)

Returns the string from the group, or "" if the group is null.

pack-priv boolean

Returns:

true if this format part has a condition.
hasCondition
()

Returns true if this format part has a condition.

public static StringBuffer
pack-priv static String

Returns:

A version of the string with any special characters replaced.
quoteSpecial
(String
The original string.
repl
,
CellFormatType
The format type representation object.
type
)

Returns a version of the original string that has any special characters quoted (or escaped) as appropriate for the cell format type.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

colorback to summary
private final Color color
COLOR_GROUPback to summary
public static final int COLOR_GROUP

Within FORMAT_PAT, the group number for the matched color.

COLOR_PATback to summary
public static final Pattern COLOR_PAT

Pattern for the color part of a cell format part.

conditionback to summary
private final CellFormatCondition condition
CONDITION_OPERATOR_GROUPback to summary
public static final int CONDITION_OPERATOR_GROUP

Within FORMAT_PAT, the group number for the operator in the condition.

CONDITION_PATback to summary
public static final Pattern CONDITION_PAT

Pattern for the condition part of a cell format part.

CONDITION_VALUE_GROUPback to summary
public static final int CONDITION_VALUE_GROUP

Within FORMAT_PAT, the group number for the value in the condition.

CURRENCY_PATback to summary
public static final Pattern CURRENCY_PAT

Pattern for the currency symbol part of a cell format part

formatback to summary
private final CellFormatter format
FORMAT_PATback to summary
public static final Pattern FORMAT_PAT

Pattern for an entire cell single part.

LOGback to summary
private static final Logger LOG
NAMED_COLORSback to summary
pack-priv static final Map<String, Color> NAMED_COLORS
SPECIFICATION_GROUPback to summary
public static final int SPECIFICATION_GROUP

Within FORMAT_PAT, the group number for the format specification.

SPECIFICATION_PATback to summary
public static final Pattern SPECIFICATION_PAT

Pattern for the format specification part of a cell format part.

typeback to summary
private final CellFormatType type

Constructor Detail

CellFormatPartback to summary
public CellFormatPart(String desc)

Create an object to represent a format part.

Parameters
desc:String

The string to parse.

CellFormatPartback to summary
public CellFormatPart(Locale locale, String desc)

Create an object to represent a format part.

Parameters
locale:Locale

The locale to use.

desc:String

The string to parse.

Method Detail

appliesback to summary
public boolean applies(Object valueObject)

Returns true if this format part applies to the given value. If the value is a number and this is part has a condition, returns true only if the number passes the condition. Otherwise, this always return true.

Parameters
valueObject:Object

The value to evaluate.

Returns:boolean

true if this format part applies to the given value.

applyback to summary
public CellFormatResult apply(Object value)

Apply this format part to the given value. This returns a CellFormatResult object with the results.

Parameters
value:Object

The value to apply this format part to.

Returns:CellFormatResult

A CellFormatResult object containing the results of applying the format to the value.

applyback to summary
public CellFormatResult apply(JLabel label, Object value)

Apply this format part to the given value, applying the result to the given label.

Parameters
label:JLabel

The label

value:Object

The value to apply this format part to.

Returns:CellFormatResult

true if the

expandCharback to summary
pack-priv static String expandChar(String part)

Expands a character. This is only partly done, because we don't have the correct info. In Excel, this would be expanded to fill the rest of the cell, but we don't know, in general, what the "rest of the cell" is.

Parameters
part:String

The character to be repeated is the second character in this string.

Returns:String

The character repeated three times.

findGroupback to summary
private static int findGroup(Pattern pat, String str, String marker)

Returns the number of the first group that is the same as the marker string. Starts from group 1.

Parameters
pat:Pattern

The pattern to use.

str:String

The string to match against the pattern.

marker:String

The marker value to find the group of.

Returns:int

The matching group number.

Exceptions
IllegalArgumentException:
No group matches the marker.
formatTypeback to summary
private CellFormatType formatType(String fdesc)

Returns the type of format.

Parameters
fdesc:String

The format specification

Returns:CellFormatType

The type of format.

getCellFormatTypeback to summary
private CellFormatType getCellFormatType(Matcher matcher)

Returns the CellFormatType object implied by the format specification for the format part.

Parameters
matcher:Matcher

The matcher for the format part.

Returns:CellFormatType

The CellFormatType.

getCellFormatTypeback to summary
pack-priv CellFormatType getCellFormatType()

Returns the CellFormatType object implied by the format specification for the format part.

Returns:CellFormatType

The CellFormatType.

getColorback to summary
private static Color getColor(Matcher m)

Returns the color specification from the matcher, or null if there is none.

Parameters
m:Matcher

The matcher for the format part.

Returns:Color

The color specification or null.

getConditionback to summary
private CellFormatCondition getCondition(Matcher m)

Returns the condition specification from the matcher, or null if there is none.

Parameters
m:Matcher

The matcher for the format part.

Returns:CellFormatCondition

The condition specification or null.

getFormatterback to summary
private CellFormatter getFormatter(Locale locale, Matcher matcher)

Returns the formatter object implied by the format specification for the format part.

Parameters
matcher:Matcher

The matcher for the format part.

Returns:CellFormatter

The formatter.

groupback to summary
public static String group(Matcher m, int g)

Returns the string from the group, or "" if the group is null.

Parameters
m:Matcher

The matcher.

g:int

The group number.

Returns:String

The group or "".

hasConditionback to summary
pack-priv boolean hasCondition()

Returns true if this format part has a condition.

Returns:boolean

true if this format part has a condition.

parseFormatback to summary
public static StringBuffer parseFormat(String fdesc, CellFormatType type, CellFormatPart.PartHandler partHandler)
quoteSpecialback to summary
pack-priv static String quoteSpecial(String repl, CellFormatType type)

Returns a version of the original string that has any special characters quoted (or escaped) as appropriate for the cell format type. The format type object is queried to see what is special.

Parameters
repl:String

The original string.

type:CellFormatType

The format type representation object.

Returns:String

A version of the string with any special characters replaced.

See Also
CellFormatType#isSpecial(char)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

org.apache.poi.ss.format back to summary

pack-priv Interface CellFormatPart.PartHandler

Known Direct Implementers
org.apache.poi.ss.format.CellNumberPartHandler, org.apache.poi.ss.format.CellDateFormatter.DatePartHandler, org.apache.poi.ss.format.CellElapsedFormatter.ElapsedPartHandler

Method Summary

Modifier and TypeMethod and Description
public String

Method Detail

handlePartback to summary
public String handlePart(Matcher m, String part, CellFormatType type, StringBuffer desc)