Write; in .CSV without separating the cell

1

I have a C # project that is normally generating a file with .CSV extension, but I want to write a; (semicolon) but it does separate the cell. Is there any way to write without this happening?

Code:

arquivo.Detalhe = new List<Detalhe>();
int sequencial = 1;
foreach (var c in clientes)
{
   Detalhe d = new Detalhe();
   var cob = c.Value.First();
   d.Endereco = c.Key.Endereco + "\";\"";

   d.Bairro = c.Key.Bairro.Nome + "\";\"";

   d.Cidade = c.Key.NomeCidade + "\";\"";
   arquivo.DetalheGD7.Add(d);
}

Creating the file:

var arquivo = Service.CriarArquivo(paraEnviar, inclusaoRadioButton.Checked, motivo);
TextFile.Serializer.Serialize(arquivo, localDoArquivoTextBox.Text + "\ARQUIVO_.CSV");

The photo of how the file comes out:

Ignore the spacing, other information that has not been populated yet.

I think there will be no need to show the other files, since my doubt is just how to write the; without the cell breaking happening.

    
asked by anonymous 25.10.2018 / 14:03

1 answer

1

According to RFC 4180, item 2.6, a field that contains line breaks, quotation marks, and the field separator MUST be printed with quotation marks around it.

See: link

Detail. You are adding ";" to the address, not just the ; , that is, its field contains the field's own separator character, which may be causing the problem instead of the semicolon.

In the same RFC, item 2.7: For a field containing quotes, the quotation marks should appear doubled.

"Endereço;";"Bairro;";Cidade
"Endereço"";""";"Bairro"";""";Cidade

It is interpreted as:

Endereço; | Bairro; | Cidade
Endereço";" | Bairro";" | Cidade

It seems confusing at first, but notice that ; gets different colors here, and that even the large amount of quotation marks continues to leave the tabs black in the right places.

    
25.10.2018 / 17:14