Class PoiExcelExporter
- All Implemented Interfaces:
IExporter,ILayerExporter
- Direct Known Subclasses:
HSSFExcelExporter
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected org.apache.poi.ss.usermodel.Drawing<?>protected booleanprotected FormulaParserprotected org.apache.poi.ss.usermodel.CreationHelperprotected NumberFormatprotected intprotected org.apache.poi.ss.usermodel.Rowprotected org.apache.poi.ss.usermodel.Sheetprotected org.apache.poi.ss.usermodel.Workbook -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract org.apache.poi.ss.usermodel.WorkbookvoidexportBegin(OutputStream outputStream) Need to be called only once at the beginning of an export operation.voidexportCell(OutputStream outputStream, Object exportDisplayValue, ILayerCell cell, IConfigRegistry configRegistry) Exports one cell.voidexportEnd(OutputStream outputStream) Need to be called only once at the end of an export operation.protected voidexportImage(InputStream is, org.apache.poi.ss.usermodel.Cell xlCell) Adds a picture to the workbook at the given cell position.voidexportLayerBegin(OutputStream outputStream, String layerName) Starts the export operation of one ILayer.voidexportLayerEnd(OutputStream outputStream, String layerName) Ends the export operation of one ILayer.voidexportRowBegin(OutputStream outputStream, int rowPosition) Starts the export operation of one row.voidexportRowEnd(OutputStream outputStream, int rowPosition) Ends the export operation of one row.protected StringgetDataFormatString(Object exportDisplayValue, ILayerCell cell, IConfigRegistry configRegistry) protected StringgetDataFormatString(ILayerCell cell, IConfigRegistry configRegistry) getOutputStream(org.eclipse.swt.widgets.Shell shell) Get theOutputStreamto which the export should be written to.voidsetApplyBackgroundColor(boolean applyBackgroundColor) voidsetApplyCellBorders(boolean apply) Configure this exporter whether it should render cell borders on all cells.voidsetApplyCellDimensions(boolean apply) Configure this exporter whether it should apply the cell dimensions to the same size configuration the NatTable shows.voidsetApplyColumnWidths(boolean apply) Configure this exporter whether it should apply the column widths to the same size configuration the NatTable shows.voidsetApplyRowHeights(boolean apply) Configure this exporter whether it should apply the row heights to the same size configuration the NatTable shows.voidsetApplyTextWrapping(boolean inspectTextWrap) Configure this exporter whether it should check for text wrapping configuration in NatTable and apply the corresponding style attribute in the export, or not.voidsetApplyVerticalTextConfiguration(boolean inspectVertical) Configure this exporter whether it should check for vertical text configuration in NatTable and apply the corresponding rotation style attribute in the export, or not.voidsetExportOnSameSheet(boolean sameSheet) Configure whether multiple table instances should be exported on the same sheet.protected abstract voidsetFillForegroundColor(org.apache.poi.ss.usermodel.CellStyle xlCellStyle, org.eclipse.swt.graphics.Color swtColor) protected abstract voidsetFontColor(org.apache.poi.ss.usermodel.Font xlFont, org.eclipse.swt.graphics.Color swtColor) voidsetFormulaParser(FormulaParser formulaParser) Configure theFormulaParserthat should be used to determine whether formulas should be exported or not.voidvoidsetSheetname(String sheetname)
-
Field Details
-
xlWorkbook
protected org.apache.poi.ss.usermodel.Workbook xlWorkbook -
sheetNumber
protected int sheetNumber -
xlSheet
protected org.apache.poi.ss.usermodel.Sheet xlSheet -
xlRow
protected org.apache.poi.ss.usermodel.Row xlRow -
formulaParser
-
nf
-
helper
protected org.apache.poi.ss.usermodel.CreationHelper helper -
drawing
protected org.apache.poi.ss.usermodel.Drawing<?> drawing -
exportOnSameSheet
protected boolean exportOnSameSheet -
currentRow
protected int currentRow
-
-
Constructor Details
-
PoiExcelExporter
-
-
Method Details
-
getOutputStream
Description copied from interface:IExporterGet theOutputStreamto which the export should be written to.- Specified by:
getOutputStreamin interfaceIExporter- Parameters:
shell- TheShellto which theILayerto export is connected to. Necessary to support user interactions via dialogs on configuring the output location.- Returns:
- The
OutputStreamto write the export to.
-
exportBegin
Description copied from interface:ILayerExporterNeed to be called only once at the beginning of an export operation. It is used to initialize the export operation like e.g. letting a user specify the export location via file selection dialog or creating a workbook.Note: Also on exporting multiple NatTable instances as part of a single export operation, this method should only be called once before any layers are exported.
- Specified by:
exportBeginin interfaceILayerExporter- Parameters:
outputStream- The OutputStream to write the export to.- Throws:
IOException- If the beginning of an export already performs I/O operations that fail.
-
exportEnd
Description copied from interface:ILayerExporterNeed to be called only once at the end of an export operation. It is used to cleanup resources after the export operation, like e.g. closing opened streams.Note: Also on exporting multiple NatTable instances as part of a single export operation, this method should only be called once after all layers are exported.
- Specified by:
exportEndin interfaceILayerExporter- Parameters:
outputStream- The OutputStream to write the export to.- Throws:
IOException- If finishing the export operation fails on an I/O operation.
-
exportLayerBegin
Description copied from interface:ILayerExporterStarts the export operation of one ILayer. Is used for example to initialize a sheet in a workbook or open the root tags in a XML format.On exporting multiple NatTable instances, this method needs to be called once for every instance.
- Specified by:
exportLayerBeginin interfaceILayerExporter- Parameters:
outputStream- The OutputStream to write the export to.layerName- The name that should be used as sheet name.- Throws:
IOException- If an error occurred during writing the export.
-
exportLayerEnd
Description copied from interface:ILayerExporterEnds the export operation of one ILayer. Is used for example to finish the export, like closing tags in a XML format.On exporting multiple NatTable instances, this method needs to be called once for every instance.
- Specified by:
exportLayerEndin interfaceILayerExporter- Parameters:
outputStream- The OutputStream to write the export to.layerName- The name that is used as sheet name. Usually not necessary, but in case there is caching involved in a custom ILayerExporter implementation, this can be used to retrieve the ILayer instance again.- Throws:
IOException- If an error occurred during writing the export.
-
exportRowBegin
Description copied from interface:ILayerExporterStarts the export operation of one row. Is used for example to initialize a row in a sheet or open some tags in a XML format.- Specified by:
exportRowBeginin interfaceILayerExporter- Parameters:
outputStream- The OutputStream to write the export to.rowPosition- The position of the row to export.- Throws:
IOException- If an error occurred during writing the export.
-
exportRowEnd
Description copied from interface:ILayerExporterEnds the export operation of one row.- Specified by:
exportRowEndin interfaceILayerExporter- Parameters:
outputStream- The OutputStream to write the export to.rowPosition- The position of the row that was exported. Usually not necessary, but in case there is caching involved in a custom ILayerExporter implementation, this can be used to retrieve the row again.- Throws:
IOException- If an error occurred during writing the export.
-
exportCell
public void exportCell(OutputStream outputStream, Object exportDisplayValue, ILayerCell cell, IConfigRegistry configRegistry) throws IOException Description copied from interface:ILayerExporterExports one cell.- Specified by:
exportCellin interfaceILayerExporter- Parameters:
outputStream- The OutputStream to write the export to.exportDisplayValue- The value that will be written to the export file. This value is determined by using the data value of the ILayerCell and the registered IExportFormatter within the NatExporter.cell- The ILayerCell that is currently exported.configRegistry- The ConfigRegistry to retrieve the registered style information of the cell that is currently exported.- Throws:
IOException- If an error occurred during writing the export.
-
getDataFormatString
protected String getDataFormatString(Object exportDisplayValue, ILayerCell cell, IConfigRegistry configRegistry) - Parameters:
exportDisplayValue- The value that should be exported.cell- The cell for which the data format needs to be determined.configRegistry- The ConfigRegistry needed to retrieve the configuration.- Returns:
- The data format that should be used to format values in the export.
- Since:
- 2.1
-
getDataFormatString
- Parameters:
cell- The cell for which the date format needs to be determined.configRegistry- The ConfigRegistry needed to retrieve the configuration.- Returns:
- The date format that should be used to format Date or Calendar values in the export.
-
setApplyBackgroundColor
public void setApplyBackgroundColor(boolean applyBackgroundColor) - Parameters:
applyBackgroundColor-trueto apply the background color set in the NatTable to the exported Excel. This also includes white background and header background color.falseif the background color should not be set on export.
-
setApplyVerticalTextConfiguration
public void setApplyVerticalTextConfiguration(boolean inspectVertical) Configure this exporter whether it should check for vertical text configuration in NatTable and apply the corresponding rotation style attribute in the export, or not.Note: As showing text vertically in NatTable is not a style information but a configured via painter implementation, the check whether text is showed vertically needs to be done via reflection. Therefore setting this value to
truecould cause performance issues. As vertical text is not the default case and the effect on performance might be negative, the default value for this configuration isfalse. If vertical text (e.g. column headers) should also be exported vertically, you need to set this value totrue.- Parameters:
inspectVertical-trueto configure this exporter to check for vertical text configuration and apply the rotation style for the export,falseto always use the regular text direction, regardless of vertical rendered text in NatTable.
-
setApplyTextWrapping
public void setApplyTextWrapping(boolean inspectTextWrap) Configure this exporter whether it should check for text wrapping configuration in NatTable and apply the corresponding style attribute in the export, or not.Note: As showing text wrapping in NatTable is not a style information but a configured via painter implementation, the check whether text is wrapped needs to be done via reflection. Therefore setting this value to
truecould cause performance issues. As wrapped text is not the default case and the effect on performance might be negative, the default value for this configuration isfalse. If wrapped text (e.g. column headers) should also be exported wrapped, you need to set this value totrue.- Parameters:
inspectTextWrap-trueto configure this exporter to check for text wrapping configuration,falseto never apply text wrapping to the export.- Since:
- 1.5
-
setApplyCellDimensions
public void setApplyCellDimensions(boolean apply) Configure this exporter whether it should apply the cell dimensions to the same size configuration the NatTable shows.- Parameters:
apply-trueto configure this exporter to apply the cell dimensions based on the NatTable cell dimensions,falseif the Excel default cell dimensions should be used.- Since:
- 1.5
-
setApplyColumnWidths
public void setApplyColumnWidths(boolean apply) Configure this exporter whether it should apply the column widths to the same size configuration the NatTable shows.- Parameters:
apply-trueto configure this exporter to apply the column widths based on the NatTable cell dimensions,falseif the Excel default cell dimensions should be used.- Since:
- 1.5
-
setApplyRowHeights
public void setApplyRowHeights(boolean apply) Configure this exporter whether it should apply the row heights to the same size configuration the NatTable shows.- Parameters:
apply-trueto configure this exporter to apply the row heights based on the NatTable cell dimensions,falseif the Excel default cell dimensions should be used.- Since:
- 1.5
-
setApplyCellBorders
public void setApplyCellBorders(boolean apply) Configure this exporter whether it should render cell borders on all cells. This should typically be enabled if background colors should be applied to make the cell borders visible.- Parameters:
apply-trueto configure this exporter to render cell borders,falseif not.- Since:
- 1.5
-
createWorkbook
protected abstract org.apache.poi.ss.usermodel.Workbook createWorkbook() -
setFillForegroundColor
protected abstract void setFillForegroundColor(org.apache.poi.ss.usermodel.CellStyle xlCellStyle, org.eclipse.swt.graphics.Color swtColor) -
setFontColor
protected abstract void setFontColor(org.apache.poi.ss.usermodel.Font xlFont, org.eclipse.swt.graphics.Color swtColor) -
getResult
- Specified by:
getResultin interfaceIExporter- Returns:
- The result that is produced by this
ITableExporter. Usually the file that is created or written by this exporter.
-
setSheetname
- Parameters:
sheetname- The name that should be set as sheet name in the resulting Excel file. Setting this value tonullwill result in a sheet name following the pattern Sheet + <sheet number>
-
setFormulaParser
Configure theFormulaParserthat should be used to determine whether formulas should be exported or not. Ifnullis set, formulas and cell values of type string will be simply exported as string. If a validFormulaParseris set, cell values will get inspected so that number values are converted to numbers and formulas will be exported as formulas.- Parameters:
formulaParser- TheFormulaParserthat should be used to determine whether cell values should be interpreted as formulas ornullto disable formula export handling.- Since:
- 1.4
-
setNumberFormat
- Parameters:
nf- TheNumberFormatthat should be used to format numeric values.
-
exportImage
Adds a picture to the workbook at the given cell position.- Parameters:
is- TheInputStreamto access the picture. This will be automatically closed after reading.xlCell- TheCellto position the image to.- Since:
- 1.5
-
setExportOnSameSheet
public void setExportOnSameSheet(boolean sameSheet) Description copied from interface:ILayerExporterConfigure whether multiple table instances should be exported on the same sheet. Only relevant for export formats that support multiple sheets like Excel.- Specified by:
setExportOnSameSheetin interfaceILayerExporter- Parameters:
sameSheet-trueif multiple NatTable instances should be exported on the same sheet,falseif every instance should be exported on separate sheets. Default isfalse.- Since:
- 1.5
-