简洁的导出 datatable到excel,不用组件

简洁的导出 datatable到excel

var lines = new List<string>();

string[] columnNames = dataTable.Columns.Cast<DataColumn>().
                                  Select(column => column.ColumnName).
                                  ToArray();

var header = string.Join(",", columnNames);
lines.Add(header);

var valueLines = dataTable.AsEnumerable()
                   .Select(row => string.Join(",", row.ItemArray));
lines.AddRange(valueLines);

File.WriteAllLines("c:\\bbbbbbbbbbbbbbb.csv", lines, Encoding.UTF8);
上一篇:csharp:Conversion Between DataTable and List


下一篇:201521123011 《java程序设计》 第9周学习总结