Class CellStyleCreator

java.lang.Object
net.sf.basedb.util.excel.CellStyleCreator

public class CellStyleCreator extends Object
Helper class for keeping track of formatting styles that has been created for given Excel worksheet. An instance of this class is needed when calling ExcelValue.writeTo(org.apache.poi.ss.usermodel.Cell, CellStyleCreator).
Since:
3.15
Author:
nicklas
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private org.apache.poi.ss.usermodel.CellStyle
     
    private final org.apache.poi.ss.usermodel.DataFormat
     
    private final Map<org.apache.poi.ss.usermodel.CellStyle,Map<String,org.apache.poi.ss.usermodel.CellStyle>>
     
    private final org.apache.poi.ss.usermodel.Workbook
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    CellStyleCreator(org.apache.poi.ss.usermodel.Workbook workbook)
    Creates a new style creator for the given Excel workbook.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Converts a Java date format string to the corresponding Excel date format string.
    org.apache.poi.ss.usermodel.Font
    Create a new font style.
    org.apache.poi.ss.usermodel.CellStyle
    Create a new cell style.
    org.apache.poi.ss.usermodel.CellStyle
    Get the current base style for new cells.
    org.apache.poi.ss.usermodel.CellStyle
    Get the cell style for the given format string.
    org.apache.poi.ss.usermodel.CellStyle
    Get the cell style for the given date format string.
    org.apache.poi.ss.usermodel.CellStyle
    Get the cell style for formatting numbers without decimals.
    void
    setBaseStyle(org.apache.poi.ss.usermodel.CellStyle baseStyle)
    Set a base style to use for new cells.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • workbook

      private final org.apache.poi.ss.usermodel.Workbook workbook
    • dataFormat

      private final org.apache.poi.ss.usermodel.DataFormat dataFormat
    • styles

      private final Map<org.apache.poi.ss.usermodel.CellStyle,Map<String,org.apache.poi.ss.usermodel.CellStyle>> styles
    • baseStyle

      private org.apache.poi.ss.usermodel.CellStyle baseStyle
  • Constructor Details

    • CellStyleCreator

      public CellStyleCreator(org.apache.poi.ss.usermodel.Workbook workbook)
      Creates a new style creator for the given Excel workbook.
  • Method Details

    • convertJavaDateFormatToExcelFormat

      public static String convertJavaDateFormatToExcelFormat(String javaFormat)
      Converts a Java date format string to the corresponding Excel date format string.
    • createStyle

      public org.apache.poi.ss.usermodel.CellStyle createStyle()
      Create a new cell style.
    • createFont

      public org.apache.poi.ss.usermodel.Font createFont()
      Create a new font style.
    • getBaseStyle

      public org.apache.poi.ss.usermodel.CellStyle getBaseStyle()
      Get the current base style for new cells.
    • setBaseStyle

      public void setBaseStyle(org.apache.poi.ss.usermodel.CellStyle baseStyle)
      Set a base style to use for new cells. When a base style has been set it used as a template for all new styles that are created with getCellStyle(String). This can be useful for setting different fonts, colors, etc.
    • getIntCellStyle

      public org.apache.poi.ss.usermodel.CellStyle getIntCellStyle()
      Get the cell style for formatting numbers without decimals. This is equivalent to getCellStyle(String) with "0" as parameter.
    • getDateCellStyle

      public org.apache.poi.ss.usermodel.CellStyle getDateCellStyle(String javaFormat)
      Get the cell style for the given date format string. If a style already exists it is re-used, otherwise a new style is created. Note that if the format string is a date format string, it must be in Java format. Use getCellStyle(String) if the format string is in Excel format.
      Parameters:
      javaFormat - The Java format string
    • getCellStyle

      public org.apache.poi.ss.usermodel.CellStyle getCellStyle(String format)
      Get the cell style for the given format string. If a style already exists it is re-used, otherwise a new style is created. Note that if the format string is a date format string, it must be in Excel format. Use getDateCellStyle(String) if the format string is in Java format.
      Parameters:
      format - The format string