我已经使用OpenXML向Excel文件写了一些内容,并尝试使用Reponse.TransmitFile
传输文件,但它无效。当我调试代码时,它不会抛出任何异常。
string filename = "Book1.xlsx";
try {
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
Response.ClearContent();
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Length", Server.MapPath("~/" + filename).Length.ToString());
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);
Response.TransmitFile(Server.MapPath("~/"+filename));
Response.Flush();
Response.End();
}
catch (Exception e) {
Console.WriteLine(e);
}