[
https://issues.apache.org/jira/browse/SANDBOX-263?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Emmanuel Bourg resolved SANDBOX-263.
------------------------------------
Resolution: Fixed
I added a note in the Javadoc explaining that the list separator is specific to
the locale. CSVFormat.EXCEL must be constant so it's not possible to guess the
separator here.
> Excel strategy uses wrong separator
> -----------------------------------
>
> Key: SANDBOX-263
> URL: https://issues.apache.org/jira/browse/SANDBOX-263
> Project: Commons Sandbox
> Issue Type: Bug
> Components: CSV
> Reporter: Gunnar Wagenknecht
>
> The Excel strategy is defined as follows.
> {code}
> public static CSVStrategy EXCEL_STRATEGY = new CSVStrategy(',', '"',
> COMMENTS_DISABLED, ESCAPE_DISABLED, false,
> false,
> false, false);
> {code}
> However, when I do a "Save as" in Excel the separator used is actually
> {{';'}}. Thus, parsing the CSV file as suggested in the JavaDoc of
> {{CSVParser}} fails.
> {code}
> String[][] data =
> (new CSVParser(new StringReader("a;b\nc;d"),
> CSVStrategy.EXCEL_STRATEGY)).getAllValues();
> {code}
> Simple test to reproduce:
> {code}
> import java.io.IOException;
> import java.io.StringReader;
> import org.apache.commons.csv.CSVParser;
> import org.apache.commons.csv.CSVStrategy;
> public class CSVExcelStrategyBug {
> public static void main(final String[] args) {
> try {
> System.out.println("Using ;");
> parse("a;b\nc;d");
> System.out.println();
> System.out.println("Using ,");
> parse("a,b\nc,d");
> } catch (final IOException e) {
> e.printStackTrace();
> }
> }
> private static void parse(final String input) throws IOException {
> final String[][] data = (new CSVParser(new StringReader(input),
> CSVStrategy.EXCEL_STRATEGY)).getAllValues();
> for (final String[] row : data) {
> System.out.print("[");
> for (final String cell : row) {
> System.out.print("(" + cell + ")");
> }
> System.out.println("]");
> }
> }
> }
> {code}
> Actual output:
> {noformat}
> Using ;
> [(a;b)]
> [(c;d)]
> Using ,
> [(a)(b)]
> [(c)(d)]
> {noformat}
> Expected output:
> {noformat}
> Using ;
> [(a)(b)]
> [(c)(d)]
> Using ,
> [(a,b)]
> [(c,d)]
> {noformat}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira