public abstract class PoiExcelExporter extends Object implements ILayerExporter
| Modifier and Type | Field and Description |
|---|---|
protected int |
currentRow |
protected org.apache.poi.ss.usermodel.Drawing |
drawing |
protected boolean |
exportOnSameSheet |
protected FormulaParser |
formulaParser |
protected org.apache.poi.ss.usermodel.CreationHelper |
helper |
protected NumberFormat |
nf |
protected int |
sheetNumber |
protected org.apache.poi.ss.usermodel.Row |
xlRow |
protected org.apache.poi.ss.usermodel.Sheet |
xlSheet |
protected org.apache.poi.ss.usermodel.Workbook |
xlWorkbook |
| Constructor and Description |
|---|
PoiExcelExporter(IOutputStreamProvider outputStreamProvider) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract org.apache.poi.ss.usermodel.Workbook |
createWorkbook() |
void |
exportBegin(OutputStream outputStream)
Need to be called only once at the beginning of an export operation.
|
void |
exportCell(OutputStream outputStream,
Object exportDisplayValue,
ILayerCell cell,
IConfigRegistry configRegistry)
Exports one cell.
|
void |
exportEnd(OutputStream outputStream)
Need to be called only once at the end of an export operation.
|
protected void |
exportImage(InputStream is,
org.apache.poi.ss.usermodel.Cell xlCell)
Adds a picture to the workbook at the given cell position.
|
void |
exportLayerBegin(OutputStream outputStream,
String layerName)
Starts the export operation of one ILayer.
|
void |
exportLayerEnd(OutputStream outputStream,
String layerName)
Ends the export operation of one ILayer.
|
void |
exportRowBegin(OutputStream outputStream,
int rowPosition)
Starts the export operation of one row.
|
void |
exportRowEnd(OutputStream outputStream,
int rowPosition)
Ends the export operation of one row.
|
protected String |
getDataFormatString(ILayerCell cell,
IConfigRegistry configRegistry) |
OutputStream |
getOutputStream(org.eclipse.swt.widgets.Shell shell)
Get the
OutputStream to which the export should be written to. |
Object |
getResult() |
void |
setApplyBackgroundColor(boolean applyBackgroundColor) |
void |
setApplyCellBorders(boolean apply)
Configure this exporter whether it should render cell borders on all
cells.
|
void |
setApplyCellDimensions(boolean apply)
Configure this exporter whether it should apply the cell dimensions to
the same size configuration the NatTable shows.
|
void |
setApplyColumnWidths(boolean apply)
Configure this exporter whether it should apply the column widths to the
same size configuration the NatTable shows.
|
void |
setApplyRowHeights(boolean apply)
Configure this exporter whether it should apply the row heights to the
same size configuration the NatTable shows.
|
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.
|
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.
|
void |
setExportOnSameSheet(boolean sameSheet) |
protected abstract void |
setFillForegroundColor(org.apache.poi.ss.usermodel.CellStyle xlCellStyle,
org.eclipse.swt.graphics.Color swtColor) |
protected abstract void |
setFontColor(org.apache.poi.ss.usermodel.Font xlFont,
org.eclipse.swt.graphics.Color swtColor) |
void |
setFormulaParser(FormulaParser formulaParser)
Configure the
FormulaParser that should be used to determine
whether formulas should be exported or not. |
void |
setNumberFormat(NumberFormat nf) |
void |
setSheetname(String sheetname) |
protected org.apache.poi.ss.usermodel.Workbook xlWorkbook
protected int sheetNumber
protected org.apache.poi.ss.usermodel.Sheet xlSheet
protected org.apache.poi.ss.usermodel.Row xlRow
protected FormulaParser formulaParser
protected NumberFormat nf
protected org.apache.poi.ss.usermodel.CreationHelper helper
protected org.apache.poi.ss.usermodel.Drawing drawing
protected boolean exportOnSameSheet
protected int currentRow
public PoiExcelExporter(IOutputStreamProvider outputStreamProvider)
public OutputStream getOutputStream(org.eclipse.swt.widgets.Shell shell)
IExporterOutputStream to which the export should be written to.getOutputStream in interface IExportershell - The Shell to which the ILayer to export is
connected to. Necessary to support user interactions via
dialogs on configuring the output location.OutputStream to write the export to.public void exportBegin(OutputStream outputStream) throws IOException
ILayerExporterNote: 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.
exportBegin in interface ILayerExporteroutputStream - The OutputStream to write the export to.IOException - If the beginning of an export already performs I/O operations
that fail.public void exportEnd(OutputStream outputStream) throws IOException
ILayerExporterNote: 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.
exportEnd in interface ILayerExporteroutputStream - The OutputStream to write the export to.IOException - If finishing the export operation fails on an I/O operation.public void exportLayerBegin(OutputStream outputStream, String layerName) throws IOException
ILayerExporterOn exporting multiple NatTable instances, this method needs to be called once for every instance.
exportLayerBegin in interface ILayerExporteroutputStream - The OutputStream to write the export to.layerName - The name that should be used as sheet name.IOException - If an error occurred during writing the export.public void exportLayerEnd(OutputStream outputStream, String layerName) throws IOException
ILayerExporterOn exporting multiple NatTable instances, this method needs to be called once for every instance.
exportLayerEnd in interface ILayerExporteroutputStream - 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.IOException - If an error occurred during writing the export.public void exportRowBegin(OutputStream outputStream, int rowPosition) throws IOException
ILayerExporterexportRowBegin in interface ILayerExporteroutputStream - The OutputStream to write the export to.rowPosition - The position of the row to export.IOException - If an error occurred during writing the export.public void exportRowEnd(OutputStream outputStream, int rowPosition) throws IOException
ILayerExporterexportRowEnd in interface ILayerExporteroutputStream - 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.IOException - If an error occurred during writing the export.public void exportCell(OutputStream outputStream, Object exportDisplayValue, ILayerCell cell, IConfigRegistry configRegistry) throws IOException
ILayerExporterexportCell in interface ILayerExporteroutputStream - 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.IOException - If an error occurred during writing the export.protected String getDataFormatString(ILayerCell cell, IConfigRegistry configRegistry)
cell - The cell for which the date format needs to be determined.configRegistry - The ConfigRegistry needed to retrieve the configuration.public void setApplyBackgroundColor(boolean applyBackgroundColor)
applyBackgroundColor - true to apply the background color set in the
NatTable to the exported Excel. This also includes white
background and header background color. false if
the background color should not be set on export.public void setApplyVerticalTextConfiguration(boolean inspectVertical)
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 true could 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 is false.
If vertical text (e.g. column headers) should also be exported
vertically, you need to set this value to true.
inspectVertical - true to configure this exporter to check for
vertical text configuration and apply the rotation style for
the export, false to always use the regular text
direction, regardless of vertical rendered text in NatTable.public void setApplyTextWrapping(boolean inspectTextWrap)
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
true could 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 is false. If wrapped
text (e.g. column headers) should also be exported wrapped, you need to
set this value to true.
inspectTextWrap - true to configure this exporter to check for text
wrapping configuration, false to never apply text
wrapping to the export.public void setApplyCellDimensions(boolean apply)
apply - true to configure this exporter to apply the cell
dimensions based on the NatTable cell dimensions,
false if the Excel default cell dimensions should
be used.public void setApplyColumnWidths(boolean apply)
apply - true to configure this exporter to apply the
column widths based on the NatTable cell dimensions,
false if the Excel default cell dimensions should
be used.public void setApplyRowHeights(boolean apply)
apply - true to configure this exporter to apply the row
heights based on the NatTable cell dimensions,
false if the Excel default cell dimensions should
be used.public void setApplyCellBorders(boolean apply)
apply - true to configure this exporter to render cell
borders, false if not.protected abstract org.apache.poi.ss.usermodel.Workbook createWorkbook()
protected abstract void setFillForegroundColor(org.apache.poi.ss.usermodel.CellStyle xlCellStyle,
org.eclipse.swt.graphics.Color swtColor)
protected abstract void setFontColor(org.apache.poi.ss.usermodel.Font xlFont,
org.eclipse.swt.graphics.Color swtColor)
public Object getResult()
getResult in interface IExporterITableExporter.
Usually the file that is created or written by this exporter.public void setSheetname(String sheetname)
sheetname - The name that should be set as sheet name in the resulting
Excel file. Setting this value to null will
result in a sheet name following the pattern Sheet +
<sheet number>public void setFormulaParser(FormulaParser formulaParser)
FormulaParser that should be used to determine
whether formulas should be exported or not. If null is set,
formulas and cell values of type string will be simply exported as
string. If a valid FormulaParser is set, cell values will get
inspected so that number values are converted to numbers and formulas
will be exported as formulas.formulaParser - The FormulaParser that should be used to determine
whether cell values should be interpreted as formulas or
null to disable formula export handling.public void setNumberFormat(NumberFormat nf)
nf - The NumberFormat that should be used to format numeric
values.protected void exportImage(InputStream is, org.apache.poi.ss.usermodel.Cell xlCell)
is - The InputStream to access the picture. This will be
automatically closed after reading.xlCell - The Cell to position the image to.public void setExportOnSameSheet(boolean sameSheet)
sameSheet - true if multiple NatTable instances should be
exported on the same sheet, false if every
instance should be exported on separate sheets. Default is
false.Copyright © 2017. All rights reserved.