Package net.sf.basedb.util.excel
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 callingExcelValue.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
baseStyle
private org.apache.poi.ss.usermodel.DataFormat
dataFormat
private Map<org.apache.poi.ss.usermodel.CellStyle,Map<String,org.apache.poi.ss.usermodel.CellStyle>>
styles
private org.apache.poi.ss.usermodel.Workbook
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
convertJavaDateFormatToExcelFormat(String javaFormat)
Converts a Java date format string to the corresponding Excel date format string.org.apache.poi.ss.usermodel.Font
createFont()
Create a new font style.org.apache.poi.ss.usermodel.CellStyle
createStyle()
Create a new cell style.org.apache.poi.ss.usermodel.CellStyle
getBaseStyle()
Get the current base style for new cells.org.apache.poi.ss.usermodel.CellStyle
getCellStyle(String format)
Get the cell style for the given format string.org.apache.poi.ss.usermodel.CellStyle
getDateCellStyle(String javaFormat)
Get the cell style for the given date format string.org.apache.poi.ss.usermodel.CellStyle
getIntCellStyle()
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.
-
-
-
Field Detail
-
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
-
-
Method Detail
-
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 withgetCellStyle(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 togetCellStyle(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. UsegetCellStyle(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. UsegetDateCellStyle(String)
if the format string is in Java format.- Parameters:
format
- The format string
-
-