使用FileHelpers动态创建CSV文件 [英] Dynamically create a CSV file with FileHelpers

查看:257
本文介绍了使用FileHelpers动态创建CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FileHelpers支持一种称为RunTime Records的功能,当您在运行时之前不知道布局时,可以将CSV文件读入DataTable。

FileHelpers supports a feature called "RunTime Records" which lets you read a CSV file into a DataTable when you don't know the layout until runtime.

可能使用FileHelpers以相同的方式在运行时创建CSV文件?

Is it possible to use FileHelpers to create a CSV file at runtime in the same manner?

根据一些用户输入,必须创建的CSV文件将具有不同的字段只有在运行时才知道。我可以创建FileHelper引擎所需的类型,如他们的阅读部分所述,但我不知道我的数据需要写入什么格式。

Based on some user input, the CSV file that must be created will have different fields that can only be known at runtime. I can create the needed Type for the FileHelper engine as described in their reading section, but I can't figure out what format my data needs to be in to be written.

var engine = new FileHelpers.FileHelperEngine(GenerateCsvType());

engine.WriteStream(context.Response.Output, dontKnow);

EDIT

或者,任何人都可以建议一个好的CSV库,可以创建一个CSV文件,而不知道其字段,直到运行时?例如,从DataTable创建一个CSV文件。

Alternatively, can anyone suggest a good CSV library that can create a CSV file without knowing its fields until runtime? For example, create a CSV file from a DataTable.

推荐答案

实际上,库只允许读取运行时记录, purpouses你可以使用DataTableToCsv方法像这样:

In fact the library only allows now to read runtime records but for writing purpouses you can use the DataTableToCsv method like this:

CsvEngine.DataTableToCsv(dt, filename);

让我知道如果有帮助。

这篇关于使用FileHelpers动态创建CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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