通过流打开一个Excel文件

            string templateExcel = "xxx.xls";
            string path = Server.MapPath(@"Template\") + templateExcel; //路径
            System.IO.FileInfo file = new System.IO.FileInfo(path);
            Response.AddHeader("Content-Disposition", "attachment;  filename=" + HttpUtility.UrlEncode(file.Name));
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();

posted on 2010-06-03 13:43  AndyCai  阅读(212)  评论(0编辑  收藏  举报

导航