使用C#中的一个CSV文件写入 [英] Writing in an CSV file using C#

查看:154
本文介绍了使用C#中的一个CSV文件写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个方式在一个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.

这篇关于使用C#中的一个CSV文件写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆