Package net.sf.basedb.util.excel
Class AutoFormatter
- java.lang.Object
-
- net.sf.basedb.util.excel.AutoFormatter
-
- All Implemented Interfaces:
ExcelFormatter<Object,Object>
public class AutoFormatter extends Object implements ExcelFormatter<Object,Object>
Excel formatter implementation that automatically selects a format depending on the type/class of the value. Null values are created as empty cells:ExcelValue.emptyCell()
Integer and Long values are created as numeric cells with no decimals:ExcelValue.asInt(Number)
Other numeric values are created as numeric cell without format specification:ExcelValue.asNumber(Number, int)
Date values with time at midnight are created as numeric cells with date formatting applied:ExcelValue.asDate(Date, String)
Date values with other times are created as numeric cells with timestamp formatting applied:ExcelValue.asTimestamp(Date, String)
Boolean values are created as numeric cells (0 or 1) with BOOLEAN format:ExcelValue.asBoolean(Boolean)
All other values are created as string values via their toString() method:ExcelValue.asString(String)
- Since:
- 3.15
- Author:
- nicklas
-
-
Field Summary
Fields Modifier and Type Field Description private String
dateFormat
private String
timestampFormat
-
Constructor Summary
Constructors Constructor Description AutoFormatter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getDateFormat()
String
getTimstampFormat()
void
setDateFormat(String dateFormat)
Set the data format template to use for date values (=dates with all time components at 0).void
setTimstampFormat(String timestampFormat)
Set the data format template to use for timestamp values.ExcelValue<Object>
toExcelValue(Object value)
Convert and format the given value to an Excel value.
-
-
-
Method Detail
-
setDateFormat
public void setDateFormat(String dateFormat)
Set the data format template to use for date values (=dates with all time components at 0). If not set, the default fromExcelValue.asDate(Date, String)
is used.
-
getDateFormat
public String getDateFormat()
- See Also:
setDateFormat(String)
-
setTimstampFormat
public void setTimstampFormat(String timestampFormat)
Set the data format template to use for timestamp values. If not set, the default fromExcelValue.asTimestamp(Date, String)
is used.
-
getTimstampFormat
public String getTimstampFormat()
- See Also:
setTimstampFormat(String)
-
toExcelValue
public ExcelValue<Object> toExcelValue(Object value)
Description copied from interface:ExcelFormatter
Convert and format the given value to an Excel value. If the value is null the implementation may return null to create an empty cell or it may return another non-null value.- Specified by:
toExcelValue
in interfaceExcelFormatter<Object,Object>
-
-