Class CsvExporter

    • Constructor Detail

      • CsvExporter

        public CsvExporter​(IOutputStreamProvider outputStreamProvider)
        Creates a CsvExporter using the given stream provider which defines the destination for the export. If the stream provider ist set to null a default FileOutputStreamProvider will be used.
        Parameters:
        outputStreamProvider - the used stream provider
      • CsvExporter

        public CsvExporter()
        Creates a CsvExporter using a default FileOutputStreamProvider to define the destination for the export.
      • CsvExporter

        public CsvExporter​(String filePath)
        Creates a CsvExporter using a FilePathOutputStreamProvider. The destination fpr the export will be a file with the given path.
        Parameters:
        filePath - the path of the export file
    • Method Detail

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

        public void setCharset​(String charset)
        Defines the name of the charset which should be used as encoding for the export file. The default ist set to windows-1252.
        Parameters:
        charset - the name of the charset
      • setDelimiter

        public void setDelimiter​(String delimiter)
        Defines the delimiter which should be used between columns. The default is the character ';'.
        Parameters:
        delimiter - the column delimiter