11package org .csuc .poi ;
22
3- import com .monitorjbl .xlsx .StreamingReader ;
43import org .apache .logging .log4j .LogManager ;
54import org .apache .logging .log4j .Logger ;
65import org .apache .poi .ss .usermodel .Sheet ;
76import org .apache .poi .ss .usermodel .Workbook ;
7+ import org .apache .poi .ss .usermodel .WorkbookFactory ;
8+ import org .apache .poi .xssf .usermodel .XSSFWorkbook ;
89import org .csuc .utils .SHEETS ;
910
1011import java .io .*;
1112import java .nio .file .Files ;
12- import java .util .*;
13+ import java .util .HashMap ;
14+ import java .util .Map ;
15+ import java .util .Objects ;
1316import java .util .regex .Matcher ;
1417import java .util .regex .Pattern ;
1518
@@ -21,50 +24,38 @@ public class XLSX2CSV {
2124
2225 private static Logger logger = LogManager .getLogger (XLSX2CSV .class );
2326
24- private Workbook workbook ;
27+ private XSSFWorkbook workbook ;
2528
2629 private char SEPARATOR ;
2730 private String ENDOFLINESYMBOLS ;
2831 private Pattern rxquote = Pattern .compile ("\" " );
2932
3033 private Map <SHEETS , File > files = new HashMap <>();
3134
32- public XLSX2CSV (String file , char delimiter , String endOfLineSymbols ) throws FileNotFoundException {
33- InputStream is = new FileInputStream (file );
34- workbook = StreamingReader .builder ()
35- .rowCacheSize (100 ) // number of rows to keep in memory (defaults to 10)
36- .bufferSize (4096 ) // buffer size to use when reading InputStream to file (defaults to 1024)
37- .open (is ); // InputStream or File for XLSX file (required)
35+ public XLSX2CSV (String file , char delimiter , String endOfLineSymbols ) throws IOException {
36+ workbook = new XSSFWorkbook (new FileInputStream (file ));
37+ //workbook = WorkbookFactory.create(new File(file));
3838 }
3939
40- public XLSX2CSV (File file , char delimiter , String endOfLineSymbols ) throws FileNotFoundException {
40+ public XLSX2CSV (File file , char delimiter , String endOfLineSymbols ) throws IOException {
4141 InputStream is = new FileInputStream (file );
4242 SEPARATOR = delimiter ;
4343 ENDOFLINESYMBOLS = endOfLineSymbols ;
44- workbook = StreamingReader .builder ()
45- .rowCacheSize (100 ) // number of rows to keep in memory (defaults to 10)
46- .bufferSize (4096 ) // buffer size to use when reading InputStream to file (defaults to 1024)
47- .open (is ); // InputStream or File for XLSX file (required)
44+ workbook = new XSSFWorkbook (new FileInputStream (file ));
4845 }
4946
50- public XLSX2CSV (String file , int rowCacheSize , int bufferSize , char delimiter , String endOfLineSymbols ) throws FileNotFoundException {
47+ public XLSX2CSV (String file , int rowCacheSize , int bufferSize , char delimiter , String endOfLineSymbols ) throws IOException {
5148 InputStream is = new FileInputStream (file );
5249 SEPARATOR = delimiter ;
5350 ENDOFLINESYMBOLS = endOfLineSymbols ;
54- workbook = StreamingReader .builder ()
55- .rowCacheSize (rowCacheSize ) // number of rows to keep in memory (defaults to 10)
56- .bufferSize (bufferSize ) // buffer size to use when reading InputStream to file (defaults to 1024)
57- .open (is ); // InputStream or File for XLSX file (required)
51+ workbook = new XSSFWorkbook (new FileInputStream (file ));
5852 }
5953
60- public XLSX2CSV (File file , int rowCacheSize , int bufferSize , char delimiter , String endOfLineSymbols ) throws FileNotFoundException {
54+ public XLSX2CSV (File file , int rowCacheSize , int bufferSize , char delimiter , String endOfLineSymbols ) throws IOException {
6155 InputStream is = new FileInputStream (file );
6256 SEPARATOR = delimiter ;
6357 ENDOFLINESYMBOLS = endOfLineSymbols ;
64- workbook = StreamingReader .builder ()
65- .rowCacheSize (rowCacheSize ) // number of rows to keep in memory (defaults to 10)
66- .bufferSize (bufferSize ) // buffer size to use when reading InputStream to file (defaults to 1024)
67- .open (is ); // InputStream or File for XLSX file (required)
58+ workbook = new XSSFWorkbook (new FileInputStream (file ));
6859 }
6960
7061 /**
@@ -110,8 +101,8 @@ private String foreachCell(Sheet sheet, int max) {
110101 boolean firstCell = true ;
111102 for (int rn = 0 ; rn < max ; rn ++) {
112103 if ( ! firstCell ) buffer .append (SEPARATOR );
113- if (row .getCell (rn ) == null || row .getCell (rn ).getStringCellValue ().isEmpty ()) buffer .append ("\" \" " );
114- else buffer .append (encodeValue (row .getCell (rn ).getStringCellValue (), SEPARATOR ));
104+ if (row .getCell (rn ) == null || row .getCell (rn ).toString ().isEmpty ()) buffer .append ("\" \" " );
105+ else buffer .append (encodeValue (row .getCell (rn ).toString (), SEPARATOR ));
115106 firstCell = false ;
116107 }
117108 buffer .append (ENDOFLINESYMBOLS );
0 commit comments