NPOI 模板 下载

 FileStream file = new FileStream(Server.MapPath(@"TemFiles\2.xls"), FileMode.Open, FileAccess.Read);

            HSSFWorkbook workbook = new HSSFWorkbook(file);

            ISheet sheet1 = workbook.GetSheetAt(0);
            IRow row1 = sheet1.CreateRow(0);

            row1.CreateCell(0).SetCellValue(1);

          
            sheet1.CreateRow(0).CreateCell(0).SetCellValue("This is a Sample");

            sheet1.GetRow(0).CreateCell(0).SetCellValue("This is a Sample");

            MemoryStream msfile = new MemoryStream(); 
            workbook.Write(msfile);
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "application/octet-stream";
            var fileName = HttpUtility.UrlEncode("2");
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls");
            Response.BinaryWrite(msfile.GetBuffer());

  

posted @ 2015-03-25 09:14  绕圈的孕妇们  阅读(104)  评论(0编辑  收藏  举报