Class CsvExporter
- java.lang.Object
-
- org.eclipse.nebula.widgets.nattable.export.csv.CsvExporter
-
- All Implemented Interfaces:
IExporter
,ILayerExporter
public class CsvExporter extends Object implements ILayerExporter
Simple CSV-Exporter ignoring cell spans.- Since:
- 1.5
-
-
Constructor Summary
Constructors Constructor Description CsvExporter()
Creates a CsvExporter using a defaultFileOutputStreamProvider
to define the destination for the export.CsvExporter(String filePath)
Creates a CsvExporter using aFilePathOutputStreamProvider
.CsvExporter(IOutputStreamProvider outputStreamProvider)
Creates a CsvExporter using the given stream provider which defines the destination for the export.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.OutputStream
getOutputStream(org.eclipse.swt.widgets.Shell shell)
Get theOutputStream
to which the export should be written to.Object
getResult()
void
setCharset(String charset)
Defines the name of the charset which should be used as encoding for the export file.void
setDelimiter(String delimiter)
Defines the delimiter which should be used between columns.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.nebula.widgets.nattable.export.ILayerExporter
setExportOnSameSheet
-
-
-
-
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 defaultFileOutputStreamProvider
will be used.- Parameters:
outputStreamProvider
- the used stream provider
-
CsvExporter
public CsvExporter()
Creates a CsvExporter using a defaultFileOutputStreamProvider
to define the destination for the export.
-
CsvExporter
public CsvExporter(String filePath)
Creates a CsvExporter using aFilePathOutputStreamProvider
. 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 theOutputStream
to which the export should be written to.- Specified by:
getOutputStream
in interfaceIExporter
- Parameters:
shell
- TheShell
to which theILayer
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 interfaceIExporter
- 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 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
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 interfaceILayerExporter
- 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 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
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 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
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 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
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 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:ILayerExporter
Exports one cell.- Specified by:
exportCell
in 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.
-
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
-
-