An Excel format has up to four parts, separated by semicolons. Each part specifies what to do with particular kinds of values, depending on the number of parts given:
[Green]#.##)[Green]#.##;[Red]#.##)[Green]#.##;[Black]#.##;[Red]#.##)[Green]#.##;[Black]#.##;[Red]#.##;[@])
A given format part may specify a given Locale, by including something
like [$$-409] or [$£-809] or [$-40C]. These
are (currently) largely ignored. You can use DateFormatConverter
to look these up into Java Locales if desired.
In addition to these, there is a general format that is used when no format
is specified.
TODO Merge this with DataFormatter so we only have one set of
code for formatting numbers.
TODO Re-use parts of this logic with ConditionalFormatting /
ConditionalFormattingRule for reporting stylings which do/don't apply
TODO Support the full set of modifiers, including alternate calendars and
native character numbers, as documented at https://help.libreoffice.org/Common/Number_Format_Codes
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private static final Map | formatCache
Maps a format string to its parsed version for efficiencies sake. |
| private final int | |
| private static final String | |
| private final Locale | |
| private static final Logger | LOG
The logger to use in the formatting code. |
| private final CellFormatPart | |
| private static final Pattern | |
| private final CellFormatPart | |
| private static final String | |
| private final CellFormatPart | |
| private final CellFormatPart |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public CellFormatResult | Returns: The result, in aCellFormatResult.The value value)Returns the result of applying the format to the given value. |
| private CellFormatResult | Returns: The result, in aCellFormatResult.The date. date, double The numeric value for the date. numericValue)Returns the result of applying the format to the given date. |
| public CellFormatResult | Returns: The result, in aCellFormatResult.The cell. c)Fetches the appropriate value from the cell, and returns the result of applying it to the appropriate format. |
| public CellFormatResult | Returns: The result, in aCellFormatResult.The label to apply to. label, Object The value to process. value)Uses the result of applying this format to the value, setting the text and color of a label before returning the result. |
| private CellFormatResult | Returns: The result, in aCellFormatResult.The label to apply to. label, Date The date. date, double The numeric value for the date. numericValue)Uses the result of applying this format to the given date, setting the text and color of a label before returning the result. |
| public CellFormatResult | Returns: The result, in aCellFormatResult.The label to apply to. label, Cell The cell. c)Fetches the appropriate value from the cell, and uses the result, setting the text and color of a label before returning the result. |
| private static CellFormat | |
| public boolean | Returns: true if the two objects are equal.The other object. obj)Overrides java. Returns |
| private CellFormatPart | Returns: TheCellFormatPart that applies to the value.The value. value)Returns the |
| public static CellFormat | Returns: A CellFormat that applies the given format.The format. format)Returns a CellFormat that applies the given format. |
| public static synchronized CellFormat | Returns: A CellFormat that applies the given format.The locale. locale, String The format. format)Returns a CellFormat that applies the given format. |
| public int | Returns: A hash code for the format.Overrides java. Returns a hash code for the format. |
| public static CellType | Returns: The ultimate type of this cell.The cell. cell)Returns the ultimate cell type, following the results of formulas. |
| format | back to summary |
|---|---|
| private final String format | |
| formatCache | back to summary |
|---|---|
| private static final Map<Locale, Map<String, CellFormat>> formatCache Maps a format string to its parsed version for efficiencies sake. | |
| formatPartCount | back to summary |
|---|---|
| private final int formatPartCount | |
| INVALID_VALUE_FOR_FORMAT | back to summary |
|---|---|
| private static final String INVALID_VALUE_FOR_FORMAT | |
| locale | back to summary |
|---|---|
| private final Locale locale | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG The logger to use in the formatting code. | |
| negNumFmt | back to summary |
|---|---|
| private final CellFormatPart negNumFmt | |
| ONE_PART | back to summary |
|---|---|
| private static final Pattern ONE_PART | |
| posNumFmt | back to summary |
|---|---|
| private final CellFormatPart posNumFmt | |
| QUOTE | back to summary |
|---|---|
| private static final String QUOTE | |
| textFmt | back to summary |
|---|---|
| private final CellFormatPart textFmt | |
| zeroNumFmt | back to summary |
|---|---|
| private final CellFormatPart zeroNumFmt | |
| CellFormat | back to summary |
|---|---|
| private CellFormat(Locale locale, String format) Creates a new object.
| |
| apply | back to summary |
|---|---|
| public CellFormatResult apply(Object value) Returns the result of applying the format to the given value. If the
value is a number (a type of
| |
| apply | back to summary |
|---|---|
| private CellFormatResult apply(Date date, double numericValue) Returns the result of applying the format to the given date.
| |
| apply | back to summary |
|---|---|
| public CellFormatResult apply(Cell c) Fetches the appropriate value from the cell, and returns the result of applying it to the appropriate format. For formula cells, the computed value is what is used.
| |
| apply | back to summary |
|---|---|
| public CellFormatResult apply(JLabel label, Object value) Uses the result of applying this format to the value, setting the text and color of a label before returning the result.
| |
| apply | back to summary |
|---|---|
| private CellFormatResult apply(JLabel label, Date date, double numericValue) Uses the result of applying this format to the given date, setting the text and color of a label before returning the result.
| |
| apply | back to summary |
|---|---|
| public CellFormatResult apply(JLabel label, Cell c) Fetches the appropriate value from the cell, and uses the result, setting the text and color of a label before returning the result.
| |
| createGeneralFormat | back to summary |
|---|---|
| private static CellFormat createGeneralFormat(final Locale locale) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Returns | |
| getApplicableFormatPart | back to summary |
|---|---|
| private CellFormatPart getApplicableFormatPart(Object value) Returns the
| |
| getInstance | back to summary |
|---|---|
| public static CellFormat getInstance(String format) Returns a CellFormat that applies the given format. Two calls with the same format may or may not return the same object.
| |
| getInstance | back to summary |
|---|---|
| public static synchronized CellFormat getInstance(Locale locale, String format) Returns a CellFormat that applies the given format. Two calls with the same format may or may not return the same object.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns a hash code for the format.
| |
| ultimateType | back to summary |
|---|---|
| public static CellType ultimateType(Cell cell) Returns the ultimate cell type, following the results of formulas. If
the cell is a | |