首页 > 代码库 > 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());
}
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。