org.apache.poi.ss.format
Class CellFormat
- java.lang.Object
-
- org.apache.poi.ss.format.CellFormat
-
public class CellFormat extends java.lang.ObjectFormat a value according to the standard Excel behavior. This "standard" is not explicitly documented by Microsoft, so the behavior is determined by experimentation; see the tests. 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:- One part (example: [Green]#.##)
- If the value is a number, display according to this one part (example: green text, with up to two decimal points). If the value is text, display it as is.
- Two parts (example: [Green]#.##;[Red]#.##)
- If the value is a positive number or zero, display according to the first part (example: green text, with up to two decimal points); if it is a negative number, display according to the second part (example: red text, with up to two decimal points). If the value is text, display it as is.
- Three parts (example: [Green]#.##;[Black]#.##;[Red]#.##)
- If the value is a positive number, display according to the first part (example: green text, with up to two decimal points); if it is zero, display according to the second part (example: black text, with up to two decimal points); if it is a negative number, display according to the third part (example: red text, with up to two decimal points). If the value is text, display it as is.
- Four parts (example: [Green]#.##;[Black]#.##;[Red]#.##;[@])
- If the value is a positive number, display according to the first part (example: green text, with up to two decimal points); if it is zero, display according to the second part (example: black text, with up to two decimal points); if it is a negative number, display according to the third part (example: red text, with up to two decimal points). If the value is text, display according to the fourth part (example: text in the cell's usual color, with the text value surround by brackets).
GENERAL_FORMATobject. TODO Merge this withDataFormatterso we only have one set of code for formatting numbers.
-
-
Field Summary
Fields Modifier and Type Field and Description static CellFormatGENERAL_FORMATFormat a value as it would be were no format specified.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description CellFormatResultapply(Cell c)Fetches the appropriate value from the cell, and returns the result of applying it to the appropriate format.CellFormatResultapply(javax.swing.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.CellFormatResultapply(javax.swing.JLabel label, java.lang.Object value)Uses the result of applying this format to the value, setting the text and color of a label before returning the result.CellFormatResultapply(java.lang.Object value)Returns the result of applying the format to the given value.booleanequals(java.lang.Object obj)Returns true if the other object is aCellFormatobject with the same format.static CellFormatgetInstance(java.lang.String format)Returns aCellFormatthat applies the given format.inthashCode()Returns a hash code for the format.static intultimateType(Cell cell)Returns the ultimate cell type, following the results of formulas.
-
-
-
Field Detail
-
GENERAL_FORMAT
public static final CellFormat GENERAL_FORMAT
Format a value as it would be were no format specified. This is also used when the format specified is General.
-
-
Method Detail
-
getInstance
public static CellFormat getInstance(java.lang.String format)
Returns aCellFormatthat applies the given format. Two calls with the same format may or may not return the same object.- Parameters:
format- The format.- Returns:
- A
CellFormatthat applies the given format.
-
apply
public CellFormatResult apply(java.lang.Object value)
Returns the result of applying the format to the given value. If the value is a number (a type ofNumberobject), the correct number format type is chosen; otherwise it is considered a text object.- Parameters:
value- The value- Returns:
- The result, in a
CellFormatResult.
-
apply
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.- Parameters:
c- The cell.- Returns:
- The result, in a
CellFormatResult.
-
apply
public CellFormatResult apply(javax.swing.JLabel label, java.lang.Object value)
Uses the result of applying this format to the value, setting the text and color of a label before returning the result.- Parameters:
label- The label to apply to.value- The value to process.- Returns:
- The result, in a
CellFormatResult.
-
apply
public CellFormatResult apply(javax.swing.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.- Parameters:
label- The label to apply to.c- The cell.- Returns:
- The result, in a
CellFormatResult.
-
ultimateType
public static int ultimateType(Cell cell)
Returns the ultimate cell type, following the results of formulas. If the cell is aCell.CELL_TYPE_FORMULA, this returns the result ofCell.getCachedFormulaResultType(). Otherwise this returns the result ofCell.getCellType().- Parameters:
cell- The cell.- Returns:
- The ultimate type of this cell.
-
equals
public boolean equals(java.lang.Object obj)
Returns true if the other object is aCellFormatobject with the same format.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- The other object.- Returns:
- true if the two objects are equal.
-
hashCode
public int hashCode()
Returns a hash code for the format.- Overrides:
hashCodein classjava.lang.Object- Returns:
- A hash code for the format.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG