Package com.levigo.jadice.server.csv
Class Csv2XlsxWorker
- java.lang.Object
-
- com.levigo.jadice.server.core.NodeWorker<T>
-
- com.levigo.jadice.server.core.StreamWorker<Csv2XlsxNode>
-
- com.levigo.jadice.server.csv.Csv2XlsxWorker
-
- All Implemented Interfaces:
QualifiedLogEventReceiver
,WorkerController<Csv2XlsxNode>
,Runnable
public class Csv2XlsxWorker extends StreamWorker<Csv2XlsxNode>
This worker allows to convert csv files into xlsx files for further conversion via MS or LibreOffice.
-
-
Constructor Summary
Constructors Constructor Description Csv2XlsxWorker()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
applyCellValuesAndInitializeEmptyCellsWithNull(com.levigo.jadice.document.io.SeekableInputStream sis, char delimiter, org.apache.poi.ss.usermodel.Sheet sheet)
Since we want to auto-size column width later on we need to initialize all the cells with value.protected void
applySingleCellValue(org.apache.poi.ss.usermodel.Cell cell, String value)
Wraps setting a cell value such that all specific actions that are needed are performed.protected void
autoSizeColumns(org.apache.poi.ss.usermodel.Workbook workbook)
Changes the cells width to the column width that is determined by poiprotected org.apache.poi.xssf.usermodel.XSSFWorkbook
convertCsvToXlsx(Stream stream, boolean landscapeMode, Short paperSize)
Converts a CSV stream into a XSSFWorkbook object.protected org.apache.poi.ss.usermodel.Sheet
createSheetAndInitializeSheet(org.apache.poi.xssf.usermodel.XSSFWorkbook workbook, boolean landscapeMode, Short paperSize)
Creates and initializes the sheet.protected char
determineDelimiter(com.levigo.jadice.document.io.SeekableInputStream csvInputStream)
Determines the delimiter of a csv file.protected void
work(Stream stream)
Implement this method in order to work on a single stream.-
Methods inherited from class com.levigo.jadice.server.core.StreamWorker
accept, reject, work
-
Methods inherited from class com.levigo.jadice.server.core.NodeWorker
abort, abortNow, addInputBundle, addOutputBundle, doAbort, doAbortNow, error, error, error, fail, fail, fail, getController, getInputBundle, getInputBundles, getJob, getLimitSupport, getNode, getOutputBundle, getOutputBundles, getServerJob, getState, getStreamTransportFactory, getTransportSender, initialize, isAbortRequested, postWork, preWork, run, setDescriptor, setJob, toString, warn, warn, warn
-
-
-
-
Method Detail
-
work
protected void work(Stream stream) throws Throwable
Description copied from class:StreamWorker
Implement this method in order to work on a single stream.- Specified by:
work
in classStreamWorker<Csv2XlsxNode>
- Parameters:
stream
- theStream
to work on- Throws:
Throwable
- in case of processing failure
-
convertCsvToXlsx
protected org.apache.poi.xssf.usermodel.XSSFWorkbook convertCsvToXlsx(Stream stream, boolean landscapeMode, Short paperSize) throws IOException
Converts a CSV stream into a XSSFWorkbook object.- Parameters:
stream
- the CSV stream- Returns:
- the converted result a XSSFWorkbook object
- Throws:
IOException
- When there is an error reading the csv stream
-
applyCellValuesAndInitializeEmptyCellsWithNull
protected void applyCellValuesAndInitializeEmptyCellsWithNull(com.levigo.jadice.document.io.SeekableInputStream sis, char delimiter, org.apache.poi.ss.usermodel.Sheet sheet) throws IOException
Since we want to auto-size column width later on we need to initialize all the cells with value. Empty cells are initialized with null values.- Parameters:
sis
- the CSV streamdelimiter
- the detected delimiter in the CSV streamsheet
- the sheet that shall be initialized- Throws:
IOException
- if reading the CSV stream fails at some point
-
applySingleCellValue
protected void applySingleCellValue(org.apache.poi.ss.usermodel.Cell cell, String value)
Wraps setting a cell value such that all specific actions that are needed are performed.- Parameters:
cell
- the cell for which the value shall be appliedvalue
- the value that is applied to the cell
-
createSheetAndInitializeSheet
protected org.apache.poi.ss.usermodel.Sheet createSheetAndInitializeSheet(org.apache.poi.xssf.usermodel.XSSFWorkbook workbook, boolean landscapeMode, Short paperSize)
Creates and initializes the sheet.- Parameters:
workbook
- The workbook for which the sheet shall be created and initializedlandscapeMode
- iftrue
the page is oriented in landscape mode, otherwise in portrait modepaperSize
- the target page dimension as short value (determined by the values in org.apache.poi.ss.usermodel.PrintSetup)- Returns:
-
autoSizeColumns
protected void autoSizeColumns(org.apache.poi.ss.usermodel.Workbook workbook)
Changes the cells width to the column width that is determined by poi- Parameters:
workbook
- the workbook that shall be adjusted
-
determineDelimiter
protected char determineDelimiter(com.levigo.jadice.document.io.SeekableInputStream csvInputStream)
Determines the delimiter of a csv file.- Parameters:
csvInputStream
- inputStream of a csv file.- Returns:
- the best guess for the file's csv delimiter.
-
-