首页 > 代码库 > 导出EXCEL
导出EXCEL
DataSource.ResultData.ReportData =http://www.mamicode.com/ dv.ToTable(); HSSFWorkbook hssfworkbook = Manager2.ExportExcel(DataSource, ReportTitleString); using (MemoryStream ms = new MemoryStream()) { hssfworkbook.Write(ms); Response.Charset = "utf-8"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(excelName, System.Text.Encoding.UTF8) + ".xls"); Response.BinaryWrite(ms.ToArray()); Response.End(); }
public ActionResult ExportToExcel() { NPOI.SS.UserModel.IWorkbook workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(); NPOI.SS.UserModel.ICell cell; NPOI.SS.UserModel.ISheet sheet = workbook.CreateSheet("StressTest"); int i = 0; int rowLimit = 100; DateTime originalTime = DateTime.Now; for (i = 0; i < rowLimit; i++) { cell = sheet.CreateRow(i).CreateCell(0); cell.SetCellValue("值" + i.ToString()); } using (MemoryStream ms = new MemoryStream()) { workbook.Write(ms); var buffer = ms.GetBuffer(); ms.Close(); return File(buffer, "application/ms-excel", "test.xlsx"); } } <p><a href="http://www.mamicode.com/@Url.Action("ExportToExcel2")">导出Excel</a></p>
来源:http://www.lanhusoft.com/Article/323.html
导出EXCEL
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。