一言不合就开始帖代码
XSSFWorkbook workbook = new XSSFWorkbook(); //创建工作簿 XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet("test"); //创建表单 XSSFRow headerRow = (XSSFRow)sheet.CreateRow(0); //创建row headerRow.CreateCell(0).SetCellValue(1); headerRow.CreateCell(1).SetCellValue(2); 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