我正在使用以下代码将数据导出到 Excel 表。
private void ExportToExcel(string fileName)
{
fileName = "MyXML.xls";
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
rptLinks.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
一切正常,但是当我尝试通过双击打开 Excel 文件MyXML.xls时,会打开一个弹出/对话框,并显示以下消息:
“您尝试打开的文件,MyXML.xls的格式与文件扩展名指定的格式不同。”等..
我们可以对代码进行一些更改,以免弹出/对话框出现吗?