简体   繁体   English

如何使用 csvhelper 有效地编写包含数千列的 csv 文件?

[英]How to efficiently write a csv file with thousands of columns using csvhelper?

I am working on measurement software from which results are written to a huge list of lists which I am trying to put into .csv file using csvhelper.我正在开发测量软件,将结果写入一个巨大的列表列表,我试图使用 csvhelper 将这些列表放入 .csv 文件。 Problem is that to keep things fairly readable and I need to create thousands of columns and I don't see any simple and effective way to do it.问题是,为了让事情具有相当的可读性,我需要创建数千列,但我没有看到任何简单有效的方法来做到这一点。

How can I create a .csv file which consist, let's say, 2000 columns?如何创建一个包含 2000 列的 .csv 文件?

EDIT 1. Sorry for my inaccurate post (it was my first ever made on StackOverflow).编辑 1. 抱歉我的帖子不准确(这是我第一次在 StackOverflow 上发表)。

Problem I am trying to solve is to create a .csv file with thousands of columns while using only a couple of lines of code so that a program will be as simple as possible.我试图解决的问题是创建一个包含数千列的 .csv 文件,同时只使用几行代码,以便程序尽可能简单。 The main reason why I want to do it that way is to keep file readable by different software for data analysis.我想这样做的主要原因是为了让不同的软件可以读取文件以进行数据分析。

What about adding properties to an ExpandoObject() (perhaps programatically in a loop) and then writing it out like so:将属性添加到 ExpandoObject()(可能在循环中以编程方式)然后像这样写出来怎么样:

void Main()
{
    var records = new List<dynamic>();

    dynamic record = new ExpandoObject();
    record.Id = 1;
    record.Name = "one";
    records.Add(record);

    using (var writer = new StringWriter())
    using (var csv = new CsvWriter(writer))
    {
        csv.WriteRecords(records);

        writer.ToString().Dump();
    }
}

https://joshclose.github.io/CsvHelper/examples/writing/write-dynamic-objects https://joshclose.github.io/CsvHelper/examples/writing/write-dynamic-objects

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM