首页 > 代码库 > mvc 导出excel
mvc 导出excel
#region 导出new方法 [NonAction] protected string RenderViewToString(Controller controller, string viewName, string masterName) { IView view = ViewEngines.Engines.FindView(controller.ControllerContext, viewName, masterName).View; using (StringWriter writer = new StringWriter()) { ViewContext viewContext = new ViewContext(controller.ControllerContext, view, controller.ViewData, controller.TempData, writer); viewContext.View.Render(viewContext, writer); return writer.ToString(); } } [NonAction] protected string RenderPartialViewToString(Controller controller, string partialViewName) { IView view = ViewEngines.Engines.FindPartialView(controller.ControllerContext, partialViewName).View; using (StringWriter writer = new StringWriter()) { ViewContext viewContext = new ViewContext(controller.ControllerContext, view, controller.ViewData, controller.TempData, writer); ViewContext viewContext1 = new ViewContext(controller.ControllerContext, view, controller.ViewData, controller.TempData, writer); viewContext.View.Render(viewContext, writer); viewContext.View.Render(viewContext1, writer); return writer.ToString(); } } public ActionResult Export(BookRequest request) { request.OrgId = this.CookieContext.OrgId; var resultList = HosService.GetWXPayReconciliation(request); ViewBag.NoPaging = true; ViewData.Model = resultList; string viewHtml = RenderPartialViewToString(this, "IndexDataList"); return File(System.Text.Encoding.UTF8.GetBytes(viewHtml), "application/ms-excel", string.Format("ccpi_{0}.xls", Guid.NewGuid())); } #endregion
在网上找到的 标记一下
用的是分布视图导出
http://www.3fwork.com/b110/001034MYM011660/
mvc 导出excel
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。