zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    用sqlite3创建数据库实现数据固化功能
    MSP430F169单片机中的LED动态显示
    在GTK中设计简单的菜单栏
    在GTK下设置窗口背景图片
    在GTK+2.0中实现简单的多用户登入系统
    ubuntu 执行sudo apt-get install libgtk2.0-devs安装gtk+-2.0时报错Failed to fetch IP:https://的解决
    Linux下Makefile,静态库,动态库的实现
    Spring 之 BeanFactory 源码
    pig trial-group,foreach
    scala
  • 原文地址:https://www.cnblogs.com/jiangyou-lz/p/6252574.html
Copyright © 2011-2022 走看看