Skip to content

Commit 78f9cb5

Browse files
committed
Merge branch 'hotfix/poi'
2 parents 59a0bcf + d8c18d8 commit 78f9cb5

File tree

2 files changed

+23
-38
lines changed

2 files changed

+23
-38
lines changed

PRC-CSV2XML-Core/pom.xml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@
8080
<groupId>org.apache.logging.log4j</groupId>
8181
<artifactId>log4j-iostreams</artifactId>
8282
</dependency>
83-
<!-- https://mvnrepository.com/artifact/com.monitorjbl/xlsx-streamer -->
84-
<dependency>
85-
<groupId>com.monitorjbl</groupId>
86-
<artifactId>xlsx-streamer</artifactId>
87-
<version>2.1.0</version>
88-
</dependency>
8983
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
9084
<dependency>
9185
<groupId>commons-io</groupId>
@@ -97,18 +91,18 @@
9791
<artifactId>poi-ooxml</artifactId>
9892
<version>4.1.0</version>
9993
</dependency>
94+
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
95+
<dependency>
96+
<groupId>org.apache.poi</groupId>
97+
<artifactId>poi-ooxml-schemas</artifactId>
98+
<version>4.1.0</version>
99+
</dependency>
100100
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-text -->
101101
<dependency>
102102
<groupId>org.apache.commons</groupId>
103103
<artifactId>commons-text</artifactId>
104104
<version>1.6</version>
105105
</dependency>
106-
<!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
107-
<dependency>
108-
<groupId>org.apache.xmlbeans</groupId>
109-
<artifactId>xmlbeans</artifactId>
110-
<version>3.1.0</version>
111-
</dependency>
112106
</dependencies>
113107

114108
<build>

PRC-CSV2XML-Core/src/main/java/org/csuc/poi/XLSX2CSV.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package org.csuc.poi;
22

3-
import com.monitorjbl.xlsx.StreamingReader;
43
import org.apache.logging.log4j.LogManager;
54
import org.apache.logging.log4j.Logger;
65
import org.apache.poi.ss.usermodel.Sheet;
76
import org.apache.poi.ss.usermodel.Workbook;
7+
import org.apache.poi.ss.usermodel.WorkbookFactory;
8+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
89
import org.csuc.utils.SHEETS;
910

1011
import java.io.*;
1112
import java.nio.file.Files;
12-
import java.util.*;
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
import java.util.Objects;
1316
import java.util.regex.Matcher;
1417
import 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

Comments
 (0)