使用C#中的一个CSV文件写入文件、CSV

2023-09-05 01:42:11 作者:是敌是友别是狗

我正在寻找一个方式在一个CSV文件的不同的单元格写的字符串。

I'm looking for a way to write strings in a different cell of a CSV file.

我使用这个程序,

    private void button1_Click(object sender, EventArgs e)
    {
        string filePath = @"E:\test.csv";  

        string a = "a";
        string b = "c";
        string c = "d";
        string d = "d";

        File.WriteAllText(filePath, a);
        // how can add the other strings in the next cells ?
    }

我需要在这里是写在第二单元一中的第一个单元格,B,C ..

What I need here is to write "a" in the first cell, "b" in the second cell, c ..

推荐答案

CSV绝对不是一个简单的文件格式,它是一个足够复杂的格式,能够涵盖几乎任何类型的数据,无论形状或大小。

CSV is absolutely NOT a SIMPLE file format, it is a sufficiently elaborate format that is able to encompass almost any kind of data regardless of shape or size.

CSV格式能够处理可选参数与非可选,数据带或不带换行的,应该可以带或不带现场在任何领域转义字符工作没有换行,并要求有现场转义字符在换行的字段。

The CSV format is capable of dealing with optional parameters vs non optional, data with or without line breaks, and should be able to work with or without field escaping characters in any field without line breaks and is required to have field escaping characters in fields with line breaks.

您应该永远不会用手工作,CSV文件,你应该利用 FileHelpers 使用CSV文件的工作。

You should not ever work with CSV files by hand, you should utilize FileHelpers to work with CSV files.

在这一点上我不再用FileHelpers作为我转到CSV解析库我使用 CsvHelper 乔什关闭。

At this point I no longer use FileHelpers as my goto CSV parsing library I use CsvHelper from Josh Close.

 
精彩推荐