Commons CSV
  1. Commons CSV
  2. CSV-23

Excel strategy uses wrong separator

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0
    • Component/s: None
    • Labels:
      None

      Description

      The Excel strategy is defined as follows.

          public static CSVStrategy EXCEL_STRATEGY   = new CSVStrategy(',', '"', COMMENTS_DISABLED, ESCAPE_DISABLED, false, 
                                                                       false, false, false);
      

      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.

      String[][] data =
         (new CSVParser(new StringReader("a;b\nc;d"), CSVStrategy.EXCEL_STRATEGY)).getAllValues();
      

      Simple test to reproduce:

      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("]");
      		}
      	}
      
      }
      

      Actual output:

      Using ;
      [(a;b)]
      [(c;d)]
      
      Using ,
      [(a)(b)]
      [(c)(d)]
      

      Expected output:

      Using ;
      [(a)(b)]
      [(c)(d)]
      
      Using ,
      [(a,b)]
      [(c,d)]
      

        Activity

        Gunnar Wagenknecht created issue -
        Gunnar Wagenknecht made changes -
        Field Original Value New Value
        Summary Excel Strategy using wrong seperator Excel sategy uses wrong seperator
        Sebb made changes -
        Summary Excel sategy uses wrong seperator Excel strategy uses wrong seperator
        Sebb made changes -
        Summary Excel strategy uses wrong seperator Excel strategy uses wrong separator
        Emmanuel Bourg made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Emmanuel Bourg made changes -
        Project Commons Sandbox [ 12310491 ] Commons CSV [ 12313222 ]
        Key SANDBOX-263 CSV-23
        Component/s CSV [ 12311182 ]
        Emmanuel Bourg made changes -
        Fix Version/s 1.0 [ 12320161 ]
        Benedikt Ritter made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Gunnar Wagenknecht
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development