我正在寻找一种在 CSV 文件的不同单元格中写入字符串的方法。
我正在使用这个程序,
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 ?
}
我这里需要的是在第一个单元格写“a”,在第二个单元格写“b”,c ..
最佳答案
CSV 是一种非常简单的文件格式,尤其是当您不需要任何单元格来包含嵌套逗号时。 CSV 表示逗号分隔值,因此您只需要一种方法来构造一个在每个单元格之间使用逗号的字符串。这将起作用,尽管它只适用于一行:
File.WriteAllText(filePath, String.Join(",", a, b, c, d));
关于c# - 使用 C# 写入 CSV 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5902346/