NPOI的excel导出2

           downExcel.aspx,以下代码放在页面的page_load里面

            string filePath = Request.QueryString["filePath"];
            string fileName = Request.QueryString["fileName"];
            FileInfo fileInfo = new FileInfo(filePath);
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
            Response.AddHeader("Content-Length", fileInfo.Length.ToString());
            Response.AddHeader("Content-Transfer-Encoding", "utf-8");
            Response.ContentType = "application/octet-stream";
            Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
            Response.ContentEncoding = System.Text.Encoding.Default;
            Response.WriteFile(fileInfo.FullName);
            Response.Flush();
            Response.End();

posted @ 2018-01-17 11:45  .net&new  阅读(86)  评论(0编辑  收藏  举报