org.eclipse.nebula.widgets.nattable.extension.poi
Class PoiExcelExporter

java.lang.Object
  extended by org.eclipse.nebula.widgets.nattable.extension.poi.PoiExcelExporter
All Implemented Interfaces:
ILayerExporter
Direct Known Subclasses:
HSSFExcelExporter

public abstract class PoiExcelExporter
extends Object
implements ILayerExporter


Field Summary
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 Summary
PoiExcelExporter(IOutputStreamProvider outputStreamProvider)
           
 
Method Summary
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.
 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)
           
 Object getResult()
           
 void setApplyBackgroundColor(boolean applyBackgroundColor)
           
 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.
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 setSheetname(String sheetname)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
Constructor Detail

PoiExcelExporter

public PoiExcelExporter(IOutputStreamProvider outputStreamProvider)
Method Detail

getOutputStream

public OutputStream getOutputStream(org.eclipse.swt.widgets.Shell shell)
Specified by:
getOutputStream in interface ILayerExporter
Parameters:
shell - The Shell where the current ILayer to export is connected to. Necessary to support user interactions via dialogs on configuring the output location.
Returns:
The OutputStream to write the export to.

exportBegin

public void exportBegin(OutputStream outputStream)
                 throws IOException
Description copied from interface: ILayerExporter
Need 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:
exportBegin in interface ILayerExporter
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

public void exportEnd(OutputStream outputStream)
               throws IOException
Description copied from interface: ILayerExporter
Need 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:
exportEnd in interface ILayerExporter
Parameters:
outputStream - The OutputStream to write the export to.
Throws:
IOException - If finishing the export operation fails on an I/O operation.

exportLayerBegin

public void exportLayerBegin(OutputStream outputStream,
                             String layerName)
                      throws IOException
Description copied from interface: ILayerExporter
Starts 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:
exportLayerBegin in interface ILayerExporter
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

public void exportLayerEnd(OutputStream outputStream,
                           String layerName)
                    throws IOException
Description copied from interface: ILayerExporter
Ends 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:
exportLayerEnd in interface ILayerExporter
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

public void exportRowBegin(OutputStream outputStream,
                           int rowPosition)
                    throws IOException
Description copied from interface: ILayerExporter
Starts 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:
exportRowBegin in interface ILayerExporter
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

public void exportRowEnd(OutputStream outputStream,
                         int rowPosition)
                  throws IOException
Description copied from interface: ILayerExporter
Ends the export operation of one row.

Specified by:
exportRowEnd in interface ILayerExporter
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: ILayerExporter
Exports one cell.

Specified by:
exportCell in interface ILayerExporter
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(ILayerCell cell,
                                     IConfigRegistry configRegistry)
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 - 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.

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 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.

Parameters:
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.

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

public Object getResult()
Specified by:
getResult in interface ILayerExporter
Returns:
The result that is produced by this ILayerExporter. Usually the file that is created or written by this exporter.

setSheetname

public void setSheetname(String sheetname)
Parameters:
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>


Copyright © 2015. All rights reserved.