Class Csv2XlsxWorker

    • Constructor Detail

      • Csv2XlsxWorker

        public Csv2XlsxWorker()
    • Method Detail

      • 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 stream
        delimiter - the detected delimiter in the CSV stream
        sheet - 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 applied
        value - 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 initialized
        landscapeMode - if true the page is oriented in landscape mode, otherwise in portrait mode
        paperSize - 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.