我正在使用下面的代码,并指定它是什么类型的应用程序。但是,当提示打开应用程序时,浏览器不知道它是什么类型的文件。我怎样才能让浏览器已经想将它作为excel打开?
任何帮助表示赞赏
public static void ExportToSpreadsheet(DataTable table, string name)
{
HttpContext context = HttpContext.Current;
context.Response.Clear();
foreach (DataColumn column in table.Columns)
{
context.Response.Write(column.ColumnName + "\t");
}
context.Response.Write(Environment.NewLine);
foreach (DataRow row in table.Rows)
{
for (int i = 0; i < table.Columns.Count; i++)
{
context.Response.Write(row[i].ToString() + "\t");
}
context.Response.Write(Environment.NewLine);
}
context.Response.ContentType = "application/ms-excel";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + name+ ".xls");
context.Response.End();
}