@@ -752,6 +752,8 @@ public static Map<String, OutputStream> excelToCsvStream(InputStream excelStream
752752 /* Iterate all the Sheets */
753753 for (ExcelSheet excelSheet : excelSheets ) {
754754 OutputStream outputStream = new ByteArrayOutputStream ();
755+
756+ /* Open CSV Writer */
755757 Writer writer = new OutputStreamWriter (outputStream );
756758 CSVWriter csvWriter = new CSVWriter (writer );
757759
@@ -776,20 +778,23 @@ public static Map<String, OutputStream> excelToCsvStream(InputStream excelStream
776778 /**
777779 * Convert a CSV file into an Excel file<p>
778780 * The default path is that of the temporary folder. By default, the filename will be the same as the input file if not specified and the extension is XLSX
781+ * @deprecated since version 0.4.0
779782 * @param fileInput The input CSV file that will be converted into an Excel file
780783 * @return An Excel file that contains the same lines as the CSV file
781784 * @throws FileAlreadyExistsException If the destination file already exists
782785 * @throws CsvValidationException If the CSV file has invalid formatting
783786 * @throws ExtensionNotValidException If the input file extension does not belong to a CSV file
784787 * @throws IOException If an I/O error has occurred
785788 */
789+ @ Deprecated
786790 public static File csvToExcel (File fileInput ) throws FileAlreadyExistsException , CsvValidationException , ExtensionNotValidException , IOException {
787791 return csvToExcel (fileInput , System .getProperty ("java.io.tmpdir" ), fileInput .getName ().split ("\\ ." )[0 ].trim (), Extension .XLSX );
788792 }
789793
790794 /**
791795 * Convert a CSV file into an Excel file<p>
792796 * The default path is that of the temporary folder. By default, the extension is XLSX
797+ * @deprecated since version 0.4.0
793798 * @param fileInput The input CSV file that will be converted into an Excel file
794799 * @param filename The name of the output file without the extension
795800 * @return An Excel file that contains the same lines as the CSV file
@@ -798,13 +803,15 @@ public static File csvToExcel(File fileInput) throws FileAlreadyExistsException,
798803 * @throws ExtensionNotValidException If the input file extension does not belong to a CSV file
799804 * @throws IOException If an I/O error has occurred
800805 */
806+ @ Deprecated
801807 public static File csvToExcel (File fileInput , String filename ) throws FileAlreadyExistsException , CsvValidationException , ExtensionNotValidException , IOException {
802808 return csvToExcel (fileInput , System .getProperty ("java.io.tmpdir" ), filename , Extension .XLSX );
803809 }
804810
805811 /**
806812 * Convert a CSV file into an Excel file<p>
807813 * By default, the extension is XLSX
814+ * @deprecated since version 0.4.0
808815 * @param fileInput The input CSV file that will be converted into an Excel file
809816 * @param path The destination path of the output file
810817 * @param filename The name of the output file without the extension
@@ -814,12 +821,14 @@ public static File csvToExcel(File fileInput, String filename) throws FileAlread
814821 * @throws ExtensionNotValidException If the input file extension does not belong to a CSV file
815822 * @throws IOException If an I/O error has occurred
816823 */
824+ @ Deprecated
817825 public static File csvToExcel (File fileInput , String path , String filename ) throws FileAlreadyExistsException , CsvValidationException , ExtensionNotValidException , IOException {
818826 return csvToExcel (fileInput , path , filename , Extension .XLSX );
819827 }
820828
821829 /**
822830 * Convert a CSV file into an Excel file
831+ * @deprecated since version 0.4.0
823832 * @param fileInput The input CSV file that will be converted into an Excel file
824833 * @param path The destination path of the output file
825834 * @param filename The name of the output file without the extension
@@ -830,6 +839,7 @@ public static File csvToExcel(File fileInput, String path, String filename) thro
830839 * @throws ExtensionNotValidException If the input file extension does not belong to a CSV file
831840 * @throws IOException If an I/O error has occurred
832841 */
842+ @ Deprecated
833843 public static File csvToExcel (File fileInput , String path , String filename , Extension extension ) throws IOException , ExtensionNotValidException , CsvValidationException , FileAlreadyExistsException {
834844 /* Check exension */
835845 String csvExt = FilenameUtils .getExtension (fileInput .getName ());
@@ -862,8 +872,61 @@ public static File csvToExcel(File fileInput, String path, String filename, Exte
862872 return outputFile ;
863873 }
864874
875+ public static byte [] csvToExcelByte (byte [] bytes , String sheetName , Extension extension ) throws CsvValidationException , ExtensionNotValidException , IOException {
876+ InputStream inputStream = new ByteArrayInputStream (bytes );
877+ ByteArrayOutputStream baos = (ByteArrayOutputStream ) csvToExcelStream (inputStream , sheetName , extension );
878+ return baos .toByteArray ();
879+ }
880+
881+ public static File csvToExcelFile (File fileInput , String sheetName , String pathname , Extension extension ) throws IOException , CsvValidationException , ExtensionNotValidException {
882+ InputStream inputStream = new FileInputStream (fileInput );
883+ ByteArrayOutputStream baos = (ByteArrayOutputStream ) csvToExcelStream (inputStream , sheetName , extension );
884+ pathname = pathname + "." + extension .getExt ();
885+ FileOutputStream fileOutputStream = new FileOutputStream (pathname );
886+ fileOutputStream .write (baos .toByteArray ());
887+ File file = new File (pathname );
888+ fileOutputStream .close ();
889+
890+ return file ;
891+ }
892+
893+ public static OutputStream csvToExcelStream (InputStream inputStream , String sheetName , Extension extension ) throws ExtensionNotValidException , CsvValidationException , IOException {
894+ /* Check the extension */
895+ if (!ExcelUtility .isValidExcelExtension (extension .getExt ())) {
896+ throw new ExtensionNotValidException ("Pass a file with the XLS or XLSX extension" );
897+ }
898+
899+ /* Open CSV Reader */
900+ Reader reader = new InputStreamReader (inputStream );
901+ CSVReader csvReader = new CSVReader (reader );
902+
903+ ExcelWorkbook excelWorkbook = new ExcelWorkbook (extension );
904+ ExcelSheet excelSheet = excelWorkbook .createSheet (sheetName );
905+
906+ /* Read CSV file */
907+ String [] values ;
908+ int cRow = 0 ;
909+ while ((values = csvReader .readNext ()) != null ) {
910+ ExcelRow excelRow = excelSheet .createRow (cRow );
911+ for (int j = 0 ; j < values .length ; j ++) {
912+ ExcelCell excelCell = excelRow .createCell (j );
913+ excelCell .writeValue (values [j ]);
914+ excelSheet .getSheet ().autoSizeColumn (j );
915+ }
916+ cRow ++;
917+ }
918+
919+ /* Write and close the Workbook */
920+ OutputStream outputStream = new ByteArrayOutputStream ();
921+ excelWorkbook .writeAndClose (outputStream );
922+ csvReader .close ();
923+
924+ return outputStream ;
925+ }
926+
865927 /**
866928 * Convert the CSV file into a new sheet of an existing File.
929+ * @deprecated since version 0.4.0
867930 * @param fileOutput The {@code File} to update
868931 * @param fileInput The input CSV file that will be converted into an Excel file
869932 * @throws OpenWorkbookException If an error occurred while opening the workbook
@@ -872,6 +935,7 @@ public static File csvToExcel(File fileInput, String path, String filename, Exte
872935 * @throws CsvValidationException If the CSV file has invalid formatting
873936 * @since 0.2.1
874937 */
938+ @ Deprecated
875939 public static void csvToExistingExcel (File fileOutput , File fileInput ) throws OpenWorkbookException , ExtensionNotValidException , IOException , CsvValidationException {
876940 /* Open workbook */
877941 ExcelWorkbook excelWorkbook = ExcelWorkbook .open (fileOutput );
@@ -888,6 +952,7 @@ public static void csvToExistingExcel(File fileOutput, File fileInput) throws Op
888952
889953 /**
890954 * Writes the data present in the CSVReader to a new sheet of an existing File.
955+ * @deprecated since version 0.4.0
891956 * @param fileOutput The {@code File} to update
892957 * @param csvReader The {@code CSVReader} of the CSV input file
893958 * @throws OpenWorkbookException If an error occurred while opening the workbook
@@ -896,6 +961,7 @@ public static void csvToExistingExcel(File fileOutput, File fileInput) throws Op
896961 * @throws CsvValidationException If the CSV file has invalid formatting
897962 * @since 0.2.1
898963 */
964+ @ Deprecated
899965 public static void csvToExistingExcel (File fileOutput , CSVReader csvReader ) throws OpenWorkbookException , ExtensionNotValidException , IOException , CsvValidationException {
900966 /* Open workbook */
901967 ExcelWorkbook excelWorkbook = ExcelWorkbook .open (fileOutput );
@@ -913,12 +979,14 @@ public static void csvToExistingExcel(File fileOutput, CSVReader csvReader) thro
913979 /**
914980 * Convert the CSV file into a new sheet of an existing Workbook.<p>
915981 * Note: This method does not call the "write" method of the workbook.
982+ * @deprecated since version 0.4.0
916983 * @param workbook The {@code Workbook} to update
917984 * @param fileInput The input CSV file that will be converted into an Excel file
918985 * @throws IOException If an I/O error has occurred
919986 * @throws CsvValidationException If the CSV file has invalid formatting
920987 * @throws ExtensionNotValidException If the input file extension does not belong to a CSV file
921988 */
989+ @ Deprecated
922990 public static void csvToExistingExcel (Workbook workbook , File fileInput ) throws IOException , CsvValidationException , ExtensionNotValidException {
923991 /* Check exension */
924992 String csvExt = FilenameUtils .getExtension (fileInput .getName ());
@@ -936,11 +1004,13 @@ public static void csvToExistingExcel(Workbook workbook, File fileInput) throws
9361004 /**
9371005 * Writes the data present in the CSVReader to a new sheet of an existing Workbook.<p>
9381006 * Note: This method does not call the "write" method of the workbook.
1007+ * @deprecated since version 0.4.0
9391008 * @param workbook The {@code Workbook} to update
9401009 * @param csvReader The {@code CSVReader} of the CSV input file
9411010 * @throws CsvValidationException If the CSV file has invalid formatting
9421011 * @throws IOException If an I/O error has occurred
9431012 */
1013+ @ Deprecated
9441014 public static void csvToExistingExcel (Workbook workbook , CSVReader csvReader ) throws CsvValidationException , IOException {
9451015 ExcelWorkbook excelWorkbook = new ExcelWorkbook (workbook );
9461016 ExcelSheet excelSheet = excelWorkbook .createSheet ();
0 commit comments