aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/build.gradle3
-rw-r--r--examples/src/main/java/org/apache/poi/examples/xssf/eventusermodel/XLSX2CSV.java14
-rw-r--r--ooxml/build.gradle18
3 files changed, 30 insertions, 5 deletions
diff --git a/examples/build.gradle b/examples/build.gradle
index 559dd449cc..15ab280aa1 100644
--- a/examples/build.gradle
+++ b/examples/build.gradle
@@ -20,4 +20,7 @@ dependencies {
implementation project(':scratchpad')
implementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
+
+ testImplementation project(path: ':ooxml', configuration: 'tests')
+ testImplementation project(path: ':main', configuration: 'tests')
}
diff --git a/examples/src/main/java/org/apache/poi/examples/xssf/eventusermodel/XLSX2CSV.java b/examples/src/main/java/org/apache/poi/examples/xssf/eventusermodel/XLSX2CSV.java
index 627e0f7fb5..81235f0ef5 100644
--- a/examples/src/main/java/org/apache/poi/examples/xssf/eventusermodel/XLSX2CSV.java
+++ b/examples/src/main/java/org/apache/poi/examples/xssf/eventusermodel/XLSX2CSV.java
@@ -128,6 +128,12 @@ public class XLSX2CSV {
for (int i=0; i<missedCols; i++) {
output.append(',');
}
+
+ // no need to append anything if we do not have a value
+ if (formattedValue == null) {
+ return;
+ }
+
currentCol = thisCol;
// Number or string?
@@ -136,8 +142,14 @@ public class XLSX2CSV {
Double.parseDouble(formattedValue);
output.append(formattedValue);
} catch (Exception e) {
+ // let's remove quotes if they are already there
+ if (formattedValue.startsWith("\"") && formattedValue.endsWith("\"")) {
+ formattedValue = formattedValue.substring(1, formattedValue.length()-1);
+ }
+
output.append('"');
- output.append(formattedValue);
+ // encode double-quote with two double-quotes to produce a valid CSV format
+ output.append(formattedValue.replace("\"", "\"\""));
output.append('"');
}
}
diff --git a/ooxml/build.gradle b/ooxml/build.gradle
index 2937e482bf..3fac94efbe 100644
--- a/ooxml/build.gradle
+++ b/ooxml/build.gradle
@@ -50,7 +50,17 @@ jar {
}
}
-test {
- // for some reason catching the OOM does not work when run from Gradle
- exclude '**/MemoryUsage.class'
-} \ No newline at end of file
+// Create a separate jar for test-code to depend on it in other projects
+// See http://stackoverflow.com/questions/5144325/gradle-test-dependency
+task testJar(type: Jar, dependsOn: testClasses) {
+ baseName = "test-${project.archivesBaseName}"
+ from sourceSets.test.output
+}
+
+configurations {
+ tests
+}
+
+artifacts {
+ tests testJar
+}