删除CSV文件中的标题 [英] Remove header in CSV file
本文介绍了删除CSV文件中的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码将datatable中的所有记录保存到csv文件中。但是当保存记录时,它还会将标题包含在csv文件中。如何从csv文件中删除标头?以下是我的代码:
Hi, i have the following codes which will save all the records in datatable into a csv file. But when the records are saved, it will also include the header into the csv file. How can i remove the header from the csv file? Below are my codes:
string targetDes = TargetFolder + "1000101_20100203_192220_Employee_Transfer_Import_36" + ".csv";
StringBuilder sb = new StringBuilder();
IEnumerable<string> columnNames = dt.Columns.Cast<DataColumn>().Select(column => column.ColumnName);
sb.AppendLine(string.Join(",", columnNames));
foreach (DataRow row in dt.Rows)
{
IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());
sb.AppendLine(string.Join(",", fields));
}
File.WriteAllText(targetDes, sb.ToString());
推荐答案
删除会做的事情
IEnumerable<string> columnNames = dt.Columns.Cast<DataColumn>().Select(column => column.ColumnName);
sb.AppendLine(string.Join(",", columnNames));
这篇关于删除CSV文件中的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文