88import com .opencsv .exceptions .CsvValidationException ;
99import enums .Extension ;
1010import exceptions .*;
11+ import model .ExcelWorkbook ;
1112import org .apache .commons .beanutils .PropertyUtils ;
1213import org .apache .commons .io .FilenameUtils ;
1314import org .apache .logging .log4j .LogManager ;
2829 */
2930public class Converter {
3031
31- private static Logger logger = LogManager .getLogger (Converter .class );
32+ private final static Logger logger = LogManager .getLogger (Converter .class );
3233
3334 /**
3435 * Convert a list of objects into an Excel file<p>
@@ -255,15 +256,16 @@ public static File objectsToExcel(List<?> objects, Class<?> clazz, String path,
255256 }
256257
257258 /* Create workbook and sheet */
258- Workbook workbook = WorkbookUtility .create (extension );
259+ ExcelWorkbook excelWorkbook = ExcelWorkbook .create (extension );
260+ Workbook workbook = excelWorkbook .getWorkbook ();
259261 objectsToExistingExcel (workbook , objects , clazz , writeHeader );
260262
261263 /* Write file */
262264 FileOutputStream fileOutputStream = new FileOutputStream (file );
263265 workbook .write (fileOutputStream );
264266
265267 /* Close file */
266- WorkbookUtility .close (workbook , fileOutputStream );
268+ excelWorkbook .close (fileOutputStream );
267269
268270 return file ;
269271 }
@@ -298,15 +300,16 @@ public static void objectsToExistingExcel(File file, List<?> objects, Class<?> c
298300 */
299301 public static void objectsToExistingExcel (File file , List <?> objects , Class <?> clazz , Boolean writeHeader ) throws OpenWorkbookException , ExtensionNotValidException , IOException , IllegalAccessException {
300302 /* Open workbook */
301- Workbook workbook = WorkbookUtility .open (file );
303+ ExcelWorkbook excelWorkbook = ExcelWorkbook .open (file );
304+ Workbook workbook = excelWorkbook .getWorkbook ();
302305 objectsToExistingExcel (workbook , objects , clazz , writeHeader );
303306
304307 /* Write file */
305308 FileOutputStream fileOutputStream = new FileOutputStream (file );
306309 workbook .write (fileOutputStream );
307310
308311 /* Close file */
309- WorkbookUtility .close (workbook , fileOutputStream );
312+ excelWorkbook .close (fileOutputStream );
310313 }
311314
312315 /**
@@ -392,7 +395,8 @@ public static List<?> excelToObjects(File file, Class<?> clazz) throws Extension
392395 */
393396 public static List <?> excelToObjects (File file , Class <?> clazz , String sheetName ) throws ExtensionNotValidException , IOException , OpenWorkbookException , InvocationTargetException , IllegalAccessException , NoSuchMethodException , InstantiationException , SheetNotFoundException , HeaderNotPresentException {
394397 /* Open file excel */
395- Workbook workbook = WorkbookUtility .open (file );
398+ ExcelWorkbook excelWorkbook = ExcelWorkbook .open (file );
399+ Workbook workbook = excelWorkbook .getWorkbook ();
396400 Sheet sheet = (sheetName == null || sheetName .isEmpty ())
397401 ? SheetUtility .get (workbook )
398402 : SheetUtility .get (workbook , sheetName );
@@ -414,7 +418,7 @@ public static List<?> excelToObjects(File file, Class<?> clazz, String sheetName
414418 }
415419
416420 /* Close file */
417- WorkbookUtility .close (workbook );
421+ excelWorkbook .close ();
418422
419423 return resultList ;
420424 }
@@ -482,7 +486,8 @@ public static File excelToCsv(File fileInput, String path, String filename) thro
482486 */
483487 public static File excelToCsv (File fileInput , String path , String filename , String sheetName ) throws ExtensionNotValidException , IOException , OpenWorkbookException , SheetNotFoundException , FileAlreadyExistsException {
484488 /* Open file excel */
485- Workbook workbook = WorkbookUtility .open (fileInput );
489+ ExcelWorkbook excelWorkbook = ExcelWorkbook .open (fileInput );
490+ Workbook workbook = excelWorkbook .getWorkbook ();
486491 Sheet sheet = (sheetName == null || sheetName .isEmpty ())
487492 ? SheetUtility .get (workbook )
488493 : SheetUtility .get (workbook , sheetName );
@@ -509,7 +514,7 @@ public static File excelToCsv(File fileInput, String path, String filename, Stri
509514 }
510515
511516 /* Close file */
512- WorkbookUtility .close (workbook , csvWriter );
517+ excelWorkbook .close (csvWriter );
513518
514519 return csvFile ;
515520 }
@@ -589,15 +594,16 @@ public static File csvToExcel(File fileInput, String path, String filename, Exte
589594 }
590595
591596 /* Create workbook and sheet */
592- Workbook workbook = WorkbookUtility .create (extension );
597+ ExcelWorkbook excelWorkbook = ExcelWorkbook .create (extension );
598+ Workbook workbook = excelWorkbook .getWorkbook ();
593599 csvToExistingExcel (workbook , csvReader );
594600
595601 /* Write file */
596602 FileOutputStream fileOutputStream = new FileOutputStream (outputFile );
597603 workbook .write (fileOutputStream );
598604
599605 /* Close file */
600- WorkbookUtility .close (workbook , fileOutputStream , csvReader );
606+ excelWorkbook .close (fileOutputStream , csvReader );
601607
602608 return outputFile ;
603609 }
@@ -614,15 +620,16 @@ public static File csvToExcel(File fileInput, String path, String filename, Exte
614620 */
615621 public static void csvToExistingExcel (File fileOutput , File fileInput ) throws OpenWorkbookException , ExtensionNotValidException , IOException , CsvValidationException {
616622 /* Open workbook */
617- Workbook workbook = WorkbookUtility .open (fileOutput );
623+ ExcelWorkbook excelWorkbook = ExcelWorkbook .open (fileOutput );
624+ Workbook workbook = excelWorkbook .getWorkbook ();
618625 csvToExistingExcel (workbook , fileInput );
619626
620627 /* Write file */
621628 FileOutputStream fileOutputStream = new FileOutputStream (fileOutput );
622629 workbook .write (fileOutputStream );
623630
624631 /* Close file */
625- WorkbookUtility .close (workbook , fileOutputStream );
632+ excelWorkbook .close (fileOutputStream );
626633 }
627634
628635 /**
@@ -637,15 +644,16 @@ public static void csvToExistingExcel(File fileOutput, File fileInput) throws Op
637644 */
638645 public static void csvToExistingExcel (File fileOutput , CSVReader csvReader ) throws OpenWorkbookException , ExtensionNotValidException , IOException , CsvValidationException {
639646 /* Open workbook */
640- Workbook workbook = WorkbookUtility .open (fileOutput );
647+ ExcelWorkbook excelWorkbook = ExcelWorkbook .open (fileOutput );
648+ Workbook workbook = excelWorkbook .getWorkbook ();
641649 csvToExistingExcel (workbook , csvReader );
642650
643651 /* Write file */
644652 FileOutputStream fileOutputStream = new FileOutputStream (fileOutput );
645653 workbook .write (fileOutputStream );
646654
647655 /* Close file */
648- WorkbookUtility .close (workbook , fileOutputStream , csvReader );
656+ excelWorkbook .close (fileOutputStream , csvReader );
649657 }
650658
651659 /**
0 commit comments