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
  • Field Details

  • Constructor Details

    • ExcelValue

      protected ExcelValue​(T value, String format)
  • Method Details

    • 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 the asDate(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 calling asNumber(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.