我正在使用:
DataTableToCSV(datatable,filepath)
创建CSV文件。哪个是生成完美的CSV。现在,如何在使用DataTableToCSV时添加列名?
答案 0 :(得分:1)
您可以使用以下内容:
[DelimitedRecord(","), IgnoreFirst(1)]
public class Person
{
// Must specify FieldOrder too
[FieldOrder(1), FieldTitle("Name")]
string name;
[FieldOrder(2), FieldTitle("Age")]
int age;
}
...
var engine = new FileHelperEngine<Person>
{
HeaderText = typeof(Person).GetCsvHeader()
};
...
engine.WriteFile(@"C:\people.csv", people);