简洁的导出 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);