码迷,mamicode.com
首页 > Windows程序 > 详细

C#添加NPOI.dll导出excel

时间:2014-12-18 15:10:38      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:c#   excel   npoi   hssfworkbook   

   var book = new HSSFWorkbook();
            var sheet = book.CreateSheet("学生信息表");
            string[] headcell = { "学号", "姓名", "年龄", "性别" };
            var row0 = sheet.CreateRow(0);
            for (int i = 0; i < headcell.Length; i++)
            {
                var cell = row0.CreateCell(i);
                cell.SetCellValue(new HSSFRichTextString(headcell[i]));
            }
            using (var ms = new MemoryStream())
            {
                book.Write(ms);
   
                Response.Clear();
                Response.ClearHeaders();
                Response.AddHeader("content-disposition", "attachment; filename=1.xls");
                Response.Buffer = true;
                Response.ContentType = "application/ms-excel";
                Response.BinaryWrite(ms.ToArray());

            }

C#添加NPOI.dll导出excel

标签:c#   excel   npoi   hssfworkbook   

原文地址:http://blog.csdn.net/u011936353/article/details/42005723

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!