CSV is actually .... Separated values ​​with a comma ... (Export Excel to AZERTY)

I'm a little confused here.

When I use Excel 2003 to export a sheet to CSV, it actually uses semicolons ...

Col1;Col2;Col3
shfdh;dfhdsfhd;fdhsdfh
dgsgsd;hdfhd;hdsfhdfsh

Now when I read csv using Microsoft drivers, it expects a comma and sees the list as one big column ???

I suspect Excel is exporting semicolons because my keyboard is AZERTY. However, should the CSV reader not be read with regard to the different separator?

How can I find out the appropriate delimiter and / or read csv correctly?

    public static DataSet ReadCsv(string fileName)
    {
        DataSet ds = new DataSet();
        string pathName = System.IO.Path.GetDirectoryName(fileName);
        string file = System.IO.Path.GetFileName(fileName);
        OleDbConnection excelConnection = new OleDbConnection
        (@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties=Text;");
        try
        {
            OleDbCommand excelCommand = new OleDbCommand(@"SELECT * FROM " + file, excelConnection);
            OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand);
            excelConnection.Open();
            excelAdapter.Fill(ds);
        }
        catch (Exception exc)
        {
            throw exc;
        }
        finally 
        {
            if(excelConnection.State != ConnectionState.Closed )
                excelConnection.Close();
        }
        return ds;
    } 
+3
source share
4 answers

- CSV; :

using (var csvReader = new CsvReader("yourinputfile.csv"))
{
    csvReader.ValueSeparator = ';';
    csvReader.ReadHeaderRecord();

    while (csvReader.HasMoreRecords)
    {
        var record = csvReader.ReadDataRecord():
        var col1 = record["Col1"];
        var col2 = record["Col2"];
    }
}
+9

, . > a > " " - "". " ". , .

+3

dendarii, CSV, Excel, , . ( Excel , , )

, , :

" " , .

Excel, , , . / (.) .

0
  • Windows 10:

Change Windows system splitter

  • , . , , ( ).

, ... , , ?

0

Source: https://habr.com/ru/post/1747313/


All Articles