Package net.sf.basedb.util.excel
Class ExcelValue<T>
- java.lang.Object
-
- net.sf.basedb.util.excel.ExcelValue<T>
-
- Direct Known Subclasses:
ExcelValue.BlankValue
,ExcelValue.BooleanValue
,ExcelValue.DateValue
,ExcelValue.IntValue
,ExcelValue.NumericValue
,ExcelValue.StringValue
public abstract class ExcelValue<T> extends Object
Represents a value and style format that should be written to a cell in an excel worksheet. Note that Excel internally only supports String and Double values. To get the intended result for integers, dates, times, etc. a format string must be applied.- Since:
- 3.15
- Author:
- nicklas
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ExcelValue.BlankValue<T>
Represents a blank cell.(package private) static class
ExcelValue.BooleanValue
Represents a cell with a numeric value.(package private) static class
ExcelValue.DateValue
Represents a cell with a date value.(package private) static class
ExcelValue.IntValue
Represents a cell with a numeric value without decimals.(package private) static class
ExcelValue.NumericValue
Represents a cell with a numeric value.(package private) static class
ExcelValue.StringValue
Represents a cell with a string value.
-
Field Summary
Fields Modifier and Type Field Description private static ExcelValue<Void>
EMPTY_CELL
private static ExcelValue<Boolean>
FALSE
protected String
format
private static ExcelValue<Boolean>
TRUE
protected T
value
-
Constructor Summary
Constructors Modifier Constructor Description protected
ExcelValue(T value, String format)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ExcelValue<Boolean>
asBoolean(Boolean value)
Create a numeric cell value with boolean format.static ExcelValue<Date>
asDate(Date value, String javaFormat)
Create a date cell value.static ExcelValue<Number>
asInt(Number value)
Create a numeric cell value without any decimals.static ExcelValue<Number>
asNumber(Number value, int numDecimals)
Create a numeric cell value and display a given number of decimals.static ExcelValue<Number>
asNumber(Number value, String format)
Create a numeric cell value with a custom numeric format.static ExcelValue<String>
asString(String value)
Create a string cell value.static ExcelValue<Date>
asTimestamp(Date value, String javaFormat)
Create a timestamp cell value.static <T> ExcelValue<T>
emptyCell()
This creates a blank cell.String
getFormat()
Get the format string.T
getValue()
Get the stored value.static String
numberFormat(int numDecimals)
Creates a format string for formatting numbers with the given number of decimals (between 0 and 15).abstract void
writeTo(org.apache.poi.ss.usermodel.Cell cell, CellStyleCreator styleCreator)
Write the value to the given cell and apply a format to it with the help of the style creator.
-
-
-
Field Detail
-
EMPTY_CELL
private static final ExcelValue<Void> EMPTY_CELL
-
TRUE
private static final ExcelValue<Boolean> TRUE
-
FALSE
private static final ExcelValue<Boolean> FALSE
-
value
protected final T value
-
format
protected final String format
-
-
Method Detail
-
emptyCell
public static final <T> ExcelValue<T> emptyCell()
This creates a blank cell.
-
asString
public static ExcelValue<String> asString(String value)
Create a string cell value.
-
asDate
public static ExcelValue<Date> asDate(Date value, String javaFormat)
Create a date cell value. The cell will be formatted according to the specified format string which should be given as a Java-compatible format string. If no format is specified "yyyy-MM-dd" is used.
-
asTimestamp
public static ExcelValue<Date> asTimestamp(Date value, String javaFormat)
Create a timestamp cell value. The cell will be formatted according to the specified format string which should be given as a Java-compatible format string. If no format is specified "yyyy-MM-dd HH:mm:ss" is used. Note! There is really no difference between this metod and theasDate(Date, String)
method except for the default format string.
-
asInt
public static final ExcelValue<Number> asInt(Number value)
Create a numeric cell value without any decimals. Same as callingasNumber(Number, int)
with 0 for the numDecimals parameter.
-
asNumber
public static final ExcelValue<Number> asNumber(Number value, int numDecimals)
Create a numeric cell value and display a given number of decimals. The numDecimals should be between 0 and 15, or the "General" format will be used.
-
asNumber
public static final ExcelValue<Number> asNumber(Number value, String format)
Create a numeric cell value with a custom numeric format.
-
asBoolean
public static final ExcelValue<Boolean> asBoolean(Boolean value)
Create a numeric cell value with boolean format.
-
numberFormat
public static String numberFormat(int numDecimals)
Creates a format string for formatting numbers with the given number of decimals (between 0 and 15).
-
getValue
public T getValue()
Get the stored value.
-
getFormat
public String getFormat()
Get the format string.
-
writeTo
public abstract void writeTo(org.apache.poi.ss.usermodel.Cell cell, CellStyleCreator styleCreator)
Write the value to the given cell and apply a format to it with the help of the style creator. If no style creator is given, the cell is not formatted.
-
-