When creating a csv file, Excel displays double quotes

I created a CSV file using C #, and when I open this file in Excel, it shows double quotes in the cells.

When I open csv in Notepad ++, I see that there are quotes and everything looks right for me. Here is part of my csv:

"CertificaatNummer", "Data", "Inleg", "Getekend", "Ingangsdatum", "Betaalmethode", "Status", "Bonus", "Aankoopkoers", "Korting", "Garantiewaarde", "Betaalde termijnen", "Inleg nominaal", "Tweede naam", "Recht op bonus maand", "Begunstigde", "Product", "Incasserekening", "Uitbetaalrekening"
"126136", "some data with, a comma", "118.34", "True", "28-1-1999 00:00:00", "Cash", "C02", "0.00", "531,940", "0,000", "0.00", "0", "0.00", "", "False", "P.H. Bloemink", "Cash-Click", "", "260952095"
"137190", "other data", "0.00", "True", "23-12-1999 00:00:00", "Cash", "C02", "0.00", "660,620", "0,000", "0,00"

When I open this file in Excel, it treats the comma some data with, a commaas a new column. This way I get "Some data within one cell and a comma"in the cell for ants. As you can see, Excel doesn't care about double quotes.

This is what my code (simplified) looks like:

var content = new List<string>();

// Add headers
content.Add("\"Header 1\", \"Header 2\", \"Header 3\", \"Header 4\"");

// Add content
content.Add("\"123456\", \"some data with, a comma\", \"118.34\", \"True\"");
// etc..

// I let a function create my file content
using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream))
{
    foreach (var line in this.content)
    {
        writer.WriteLine(line);
    }

    writer.Flush();
    return stream.ToArray();
}

// finally I return the file content to the browser with 
// HttpContext.Response.AddHeader("content-disposition", "file;name=" + fileName);

The question is, what part of my code do I need to change so that Excel displays my file correctly? I rather want to change my code and then do some tricks in Excel.

+4
3

.

"some, text","Other text"

:

"some, text",<space>"Other text"

, Excel CSV . , .

+10

, Excel CSV , UTF-16LE, ( ASCII 9) . ( ) .

0

Just write a comma with the "\" character.

Or, if you do it programmatically, just use the Replace(",","\,")method

-1
source

All Articles