首页 > 代码库 > C#添加NPOI.dll导出excel

C#添加NPOI.dll导出excel

   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