一言不合就开始帖代码
XSSFWorkbook workbook = new XSSFWorkbook(); //创建工作簿
XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet("test"); //创建表单
XSSFRow headerRow = (XSSFRow)sheet.CreateRow(); //创建row
headerRow.CreateCell().SetCellValue();
headerRow.CreateCell().SetCellValue(); using (MemoryStream ms = new MemoryStream())
{
workbook.Write(ms);
ms.Flush();
//Response.Write(ms);
Response.BinaryWrite(ms.ToArray());
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.AppendHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode("test", System.Text.Encoding.UTF8) + ".xlsx");
Response.End();
}
通过NPOI从内存流中创建EXCEL