Class AbstractExcelDataExporter
- java.lang.Object
-
- org.apache.wicket.extensions.markup.html.repeater.data.table.export.AbstractDataExporter
-
- org.wicketstuff.poi.datatable.export.AbstractExcelDataExporter
-
- All Implemented Interfaces:
Serializable,IDataExporter,IClusterable
- Direct Known Subclasses:
ExcelDataExporter,OOXMLDataExporter
public abstract class AbstractExcelDataExporter extends AbstractDataExporter
An abstractIDataExporterthat exports to a POIWorkbook. This has an abstract factory method to create a newWorkbook. This can be overridden to provide either aHSSFWorkbookor aXSSFWorkbook.- Author:
- Jesse Long
- See Also:
ExcelDataExporter,OOXMLDataExporter, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractExcelDataExporter(IModel<String> dataFormatNameModel, String contentType, String fileNameExtension)Creates a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract org.apache.poi.ss.usermodel.WorkbookcreateWorkbook()Creates a newWorkbookto which the exported data will be added.<T> voidexportData(IDataProvider<T> dataProvider, List<IExportableColumn<T,?>> columns, OutputStream outputStream)Exports data to a ExcelWorkbook.protected <T> voidpopulateCell(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 voidpopulateHeaderCell(org.apache.poi.ss.usermodel.Cell cell, String value, int columnIndex, IExportableColumn<?,?> column, org.apache.poi.ss.usermodel.Workbook workbook)Populates a header cell.-
Methods inherited from class org.apache.wicket.extensions.markup.html.repeater.data.table.export.AbstractDataExporter
getContentType, getDataFormatNameModel, getFileNameExtension, setContentType, setDataFormatNameModel, setFileNameExtension
-
-
-
-
Constructor Detail
-
AbstractExcelDataExporter
public AbstractExcelDataExporter(IModel<String> dataFormatNameModel, String contentType, String fileNameExtension)
Creates a new instance.- Parameters:
dataFormatNameModel- AnIModelof 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 ".".
-
-
Method Detail
-
createWorkbook
protected abstract org.apache.poi.ss.usermodel.Workbook createWorkbook()
Creates a newWorkbookto which the exported data will be added. This should be either aHSSFWorkbookor aXSSFWorkbook.- Returns:
- a new
Workbookto which the exported data will be added.
-
exportData
public <T> void exportData(IDataProvider<T> dataProvider, List<IExportableColumn<T,?>> columns, OutputStream outputStream) throws IOException
Exports data to a ExcelWorkbook.- Type Parameters:
T- The type of each row in the exported data.- Parameters:
dataProvider- TheIDataProviderfrom which the row data is retrieved.columns- AListofIExportableColumns which can be exported.outputStream- TheOutputStreamto which the exported spreadsheet will be written.- Throws:
IOException- If an error occurs while exporting the data.
-
populateHeaderCell
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. This can be overridden to decorate header cells, or to add some custom header cell populating code.- Parameters:
cell- TheCellto be populated.value- The header description, as returned fromIExportableColumn.getDisplayModel(). This can benull.columnIndex- The index of the column being populated. This is zero based.column- TheIExportableColumnfor which the cell is being exported.workbook- TheWorkbookin which the cell is created. This is included to than it may be used to create formatting objects etc.
-
populateCell
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. This can be overridden to provide custom cell population behavior, or to decorate the cell.- Type Parameters:
T- The type of each exported row.- Parameters:
cell- TheCellto be populated.rowModel- TheIModelof the row.column- TheIExportableColumnfor 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- TheWorkbookin which the cell is created. This is included to than it may be used to create formatting objects etc.
-
-