改代码段主要是弹出导出Excel的对话框:
string headerEncodeStr = "GB2312";
string contentEncodeStr = "GB2312";
string filePath = Server.MapPath("../TemplateFiles/CarInformation.xls");
string fileName = "物品信息";// "CarInformation";
fileName = HttpUtility.UrlEncode(fileName);//防止导出文件名是乱码
System.Web.HttpContext currContent = System.Web.HttpContext.Current;
currContent.Response.HeaderEncoding = System.Text.Encoding.GetEncoding(headerEncodeStr);
currContent.Response.AddHeader("Content-Disposition", "inline;attachment;filename=" + fileName + ".xls");
currContent.Response.ContentEncoding = System.Text.Encoding.GetEncoding(contentEncodeStr);
currContent.Response.Charset = contentEncodeStr;
currContent.Response.ContentType = "application/ms-excel";
currContent.Response.BinaryWrite(System.IO.File.ReadAllBytes(filePath)); //读取二进制文件输出
currContent.Response.End();