Package net.sf.basedb.util.excel
Class CellStyleCreator
java.lang.Object
net.sf.basedb.util.excel.CellStyleCreator
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
-
Constructor Summary
ConstructorDescriptionCellStyleCreator
(org.apache.poi.ss.usermodel.Workbook workbook) Creates a new style creator for the given Excel workbook. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
convertJavaDateFormatToExcelFormat
(String javaFormat) 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
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
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 Details
-
workbook
private final org.apache.poi.ss.usermodel.Workbook workbook -
dataFormat
private final org.apache.poi.ss.usermodel.DataFormat dataFormat -
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
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
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
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
-