Package com.groiss.gui.excel
Class ExcelUtils
java.lang.Object
com.groiss.gui.excel.ExcelUtils
Utility class for creating Excel files.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.poi.ss.usermodel.Cell
createDataCell
(org.apache.poi.ss.usermodel.Row row, int col, Object value, org.apache.poi.ss.usermodel.CellStyle basicStyle, org.apache.poi.ss.usermodel.CellStyle floatStyle, org.apache.poi.ss.usermodel.CellStyle decimalStyle, org.apache.poi.ss.usermodel.CellStyle dateStyle, org.apache.poi.ss.usermodel.CellStyle textStyle, org.apache.poi.ss.usermodel.CreationHelper ch) Creates aCell
object in the given row and column.static org.apache.poi.ss.usermodel.Cell
createHeaderCell
(org.apache.poi.ss.usermodel.Row row, int col, org.apache.poi.ss.usermodel.CellStyle style, String value) Get a new headerCell
object with given informationstatic org.apache.poi.ss.usermodel.Workbook
exportToWorkbook
(String title, List<Map<String, Object>> data, NavigationTreeNode n, List<String> selectedCols) Export a list of given data to Excel.static org.apache.poi.ss.usermodel.Workbook
exportToWorkbook
(String title, TableModel tm, NavigationTreeNode n) Export aTableModel
to Excel.static org.apache.poi.ss.usermodel.Workbook
exportToWorkbook
(String title, TableModel tm, NavigationTreeNode n, List<String> selectedCols) Export aTableModel
to Excel.static org.apache.poi.ss.usermodel.Font
getArialFont
(org.apache.poi.ss.usermodel.Workbook book) Creates a standardFont
object with font Arial.static org.apache.poi.ss.usermodel.CellStyle
getBasicStyle
(org.apache.poi.ss.usermodel.Workbook book) Creates a basicCellStyle
object which is used a default object for other special styles (e.g. decimal, etc.).static org.apache.poi.ss.usermodel.Cell
getCell
(org.apache.poi.ss.usermodel.Row row, org.apache.poi.ss.usermodel.CellStyle style, int col) Get a newCell
object with given informationstatic org.apache.poi.ss.usermodel.CellStyle
getDateStyle
(org.apache.poi.ss.usermodel.Workbook book) static org.apache.poi.ss.usermodel.CellStyle
getDecimalStyle
(org.apache.poi.ss.usermodel.Workbook book) static org.apache.poi.ss.usermodel.CellStyle
getFloatStyle
(org.apache.poi.ss.usermodel.Workbook book) static org.apache.poi.ss.usermodel.CellStyle
getTextStyle
(org.apache.poi.ss.usermodel.Workbook book) Creates aCellStyle
object for ordinary texts
-
Method Details
-
getCell
public static org.apache.poi.ss.usermodel.Cell getCell(org.apache.poi.ss.usermodel.Row row, org.apache.poi.ss.usermodel.CellStyle style, int col) Get a newCell
object with given information- Parameters:
row
- the row where cell should be createdstyle
- the style of the cellcol
- the column number the cell represents- Returns:
- the
Cell
object
-
createHeaderCell
public static org.apache.poi.ss.usermodel.Cell createHeaderCell(org.apache.poi.ss.usermodel.Row row, int col, org.apache.poi.ss.usermodel.CellStyle style, String value) Get a new headerCell
object with given information- Parameters:
row
- the row where cell should be created (should be the header row)col
- the column number the cell representsstyle
- the style of the cellvalue
- a rich string value for the cell- Returns:
- the
Cell
object
-
createDataCell
public static org.apache.poi.ss.usermodel.Cell createDataCell(org.apache.poi.ss.usermodel.Row row, int col, Object value, org.apache.poi.ss.usermodel.CellStyle basicStyle, org.apache.poi.ss.usermodel.CellStyle floatStyle, org.apache.poi.ss.usermodel.CellStyle decimalStyle, org.apache.poi.ss.usermodel.CellStyle dateStyle, org.apache.poi.ss.usermodel.CellStyle textStyle, org.apache.poi.ss.usermodel.CreationHelper ch) Creates aCell
object in the given row and column. Configure the cell according to type of value.- Parameters:
row
- the row where cell is locatedcol
- the column number the cell representsvalue
- the value to enrich the cell value. FollowingbasicStyle
- the basic style which is used for cells with empty value or if no value conversion was possible (= an error occurred)floatStyle
- the style used forNumber
values of typeFloat
orDouble
decimalStyle
- the style used forNumber
values which are not of typeFloat
orDouble
dateStyle
- the style used forDate
valuestextStyle
- the style used for all other values that does not corresponds with other stylesch
- aCreationHelper
object to create a rich text string for cells where- no value exists (= empty value)
- a value exists with style type 'textStyle'
- a conversion of the value was not possible (= an error occurred)
- Returns:
- the
Cell
object
-
getDecimalStyle
public static org.apache.poi.ss.usermodel.CellStyle getDecimalStyle(org.apache.poi.ss.usermodel.Workbook book) - Parameters:
book
- the workbook to create theCellStyle
object- Returns:
- the
CellStyle
object
-
getTextStyle
public static org.apache.poi.ss.usermodel.CellStyle getTextStyle(org.apache.poi.ss.usermodel.Workbook book) Creates aCellStyle
object for ordinary texts- Parameters:
book
- the workbook to create theCellStyle
object- Returns:
- the
CellStyle
object
-
getBasicStyle
public static org.apache.poi.ss.usermodel.CellStyle getBasicStyle(org.apache.poi.ss.usermodel.Workbook book) Creates a basicCellStyle
object which is used a default object for other special styles (e.g. decimal, etc.). Following basic styles are set:- Foreground color of the cell is set to white
- A thin border is defined for the cell
- Parameters:
book
- the workbook to create theCellStyle
object- Returns:
- the
CellStyle
object
-
getFloatStyle
public static org.apache.poi.ss.usermodel.CellStyle getFloatStyle(org.apache.poi.ss.usermodel.Workbook book) Creates aCellStyle
object for decimal values which are of typeFloat
orDouble
.
The format is: #,##0.00- Parameters:
book
- the workbook to create theCellStyle
object- Returns:
- the
CellStyle
object
-
getDateStyle
public static org.apache.poi.ss.usermodel.CellStyle getDateStyle(org.apache.poi.ss.usermodel.Workbook book) - Parameters:
book
- the workbook to create theCellStyle
object- Returns:
- the
CellStyle
object
-
getArialFont
public static org.apache.poi.ss.usermodel.Font getArialFont(org.apache.poi.ss.usermodel.Workbook book) Creates a standardFont
object with font Arial.- Parameters:
book
- the workbook to create theFont
object- Returns:
- the
Font
object