public abstract class AbstractExcelDataExporter extends AbstractDataExporter
IDataExporter that exports to a POI Workbook. This has an abstract factory method to create a new
Workbook. This can be overridden to provide either a HSSFWorkbook or a XSSFWorkbook.ExcelDataExporter,
OOXMLDataExporter,
Serialized Form| Constructor and Description |
|---|
AbstractExcelDataExporter(IModel<String> dataFormatNameModel,
String contentType,
String fileNameExtension)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract org.apache.poi.ss.usermodel.Workbook |
createWorkbook()
Creates a new
Workbook to which the exported data will be added. |
<T> void |
exportData(IDataProvider<T> dataProvider,
List<IExportableColumn<T,?>> columns,
OutputStream outputStream)
Exports data to a Excel
Workbook. |
protected <T> void |
populateCell(org.apache.poi.ss.usermodel.Cell cell,
IModel<T> rowModel,
IExportableColumn<T,?> column,
int rowIndex,
int columnIndex,
org.apache.poi.ss.usermodel.Workbook workbook)
Populates a cell of exported data.
|
protected void |
populateHeaderCell(org.apache.poi.ss.usermodel.Cell cell,
String value,
int columnIndex,
IExportableColumn<?,?> column,
org.apache.poi.ss.usermodel.Workbook workbook)
Populates a header cell.
|
getContentType, getDataFormatNameModel, getFileNameExtension, setContentType, setDataFormatNameModel, setFileNameExtensionpublic AbstractExcelDataExporter(IModel<String> dataFormatNameModel, String contentType, String fileNameExtension)
dataFormatNameModel - An IModel of the data format name.contentType - The MIME content type to use when serving up the exported data.fileNameExtension - The file name extensions to use for the exported file. This should exclude the ".".protected abstract org.apache.poi.ss.usermodel.Workbook createWorkbook()
Workbook to which the exported data will be added. This should be either a HSSFWorkbook or
a XSSFWorkbook.Workbook to which the exported data will be added.public <T> void exportData(IDataProvider<T> dataProvider, List<IExportableColumn<T,?>> columns, OutputStream outputStream) throws IOException
Workbook.T - The type of each row in the exported data.dataProvider - The IDataProvider from which the row data is retrieved.columns - A List of IExportableColumns which can be exported.outputStream - The OutputStream to which the exported spreadsheet will be written.IOException - If an error occurs while exporting the data.protected void populateHeaderCell(org.apache.poi.ss.usermodel.Cell cell,
String value,
int columnIndex,
IExportableColumn<?,?> column,
org.apache.poi.ss.usermodel.Workbook workbook)
cell - The Cell to be populated.value - The header description, as returned from IExportableColumn.getDisplayModel(). This can be
null.columnIndex - The index of the column being populated. This is zero based.column - The IExportableColumn for which the cell is being exported.workbook - The Workbook in which the cell is created. This is included to than it may be used to create
formatting objects etc.protected <T> void populateCell(org.apache.poi.ss.usermodel.Cell cell,
IModel<T> rowModel,
IExportableColumn<T,?> column,
int rowIndex,
int columnIndex,
org.apache.poi.ss.usermodel.Workbook workbook)
T - The type of each exported row.cell - The Cell to be populated.rowModel - The IModel of the row.column - The IExportableColumn for which this cell if being populated.rowIndex - The zero based index of this row in the data set. If headers are exported. then the row index in the
spreadsheet will be one more than this, because the first row of the spreadsheet contains headers.columnIndex - The zero based index of the column.workbook - The Workbook in which the cell is created. This is included to than it may be used to create
formatting objects etc.Copyright © 2019. All rights reserved.