java.lang.Object
org.eclipse.nebula.widgets.nattable.export.excel.ExcelExporter
All Implemented Interfaces:
IExporter, ILayerExporter

public class ExcelExporter extends Object implements ILayerExporter
This class is used to export a NatTable to an Excel spreadsheet by using a XML format.
  • Constructor Details

    • ExcelExporter

      public ExcelExporter()
      Creates a new ExcelExporter using a FileOutputStreamProvider with default values.
    • ExcelExporter

      public ExcelExporter(IOutputStreamProvider outputStreamProvider)
      Creates a new ExcelExporter that uses the given IOutputStreamProvider for retrieving the OutputStream to write the export to.
      Parameters:
      outputStreamProvider - The IOutputStreamProvider that is used to retrieve the OutputStream to write the export to.
  • Method Details

    • getOutputStream

      public OutputStream getOutputStream(org.eclipse.swt.widgets.Shell shell)
      Description copied from interface: IExporter
      Get the OutputStream to which the export should be written to.
      Specified by:
      getOutputStream in interface IExporter
      Parameters:
      shell - The Shell to which the 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.
    • getResult

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

      public void setCharset(String charset)
      Parameters:
      charset - The charset that should be used as replacement for the charset value in the export header. Default is windows-1252
    • setSheetname

      public void setSheetname(String sheetname)
      Parameters:
      sheetname - The name that should be set as sheet name in the resulting Excel file. Default is Sheet1