Use method Excelhelper.datatabletocsv (dt,@ "D:\1212.xls"); System.Diagnostics.Process.Start (@ "C:\1.xls"); Open Excel File
public static void Datatabletocsv (DataTable table, string file)
{
string title = "";
FileStream fs = new FileStream (file, FileMode.OpenOrCreate);
FileStream FS1 = File.Open (File, FileMode.Open, FileAccess.Read);
StreamWriter SW = new StreamWriter (new BufferedStream (FS), System.Text.Encoding.Default);
for (int i = 0; i < table. Columns.count; i++)
{
Title + = table. Columns[i]. ColumnName + "\ T"; Fields: Automatically jumps to the next cell
}
title = title. Substring (0, title. Length-1) + "\ n";
Sw. Write (title);
foreach (DataRow row in table. Rows)
{
String line = "";
for (int i = 0; i < table. Columns.count; i++)
{
Line + = Row[i]. ToString (). Trim () + "\ T"; Content: Automatically jumps to the next cell
}
line = line. Substring (0, line. Length-1) + "\ n";
Sw. Write (line);
}
Sw. Close ();
Fs. Close ();
}
Asp. NET's quick way to export Excel, DataTable export Excel (Pro-Test, non-original)