Most CSV formats use "" (two quotes) to escape a "-character, we should do this in this
example as well to produce files that can be parsed by other CSV processors correctly.
Also cases where the value is already enclosed in quotes should not lead to additional quotes
Add a simple initial test to module "examples" verify basic functionality of XSLX2CSV
as I often rely on it for converting some very large xlsx-files to csv
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@
1888418 13f79535-47bb-0310-9956-
ffa450edef68
implementation project(':scratchpad')
implementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
+
+ testImplementation project(path: ':ooxml', configuration: 'tests')
+ testImplementation project(path: ':main', configuration: 'tests')
}
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?
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('"');
}
}
}
}
-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
+}