Ejemplo n.º 1
0
        public ActionResult DynamicExportDemo()
        {
            // 1.获取数据源
            DataSet dataSource = GetDataSourceForDynamicExportDemo();

            // 2.生成报表
            string templatePath = SysContext.Config.ReportTemplateDirectory_Physical + "Excel动态报表模版Demo.xlsx";
            ExcelReport_Dynamic <DynamicExcelDataViewModel> dynamicReport = new ExcelReport_Dynamic <DynamicExcelDataViewModel>(templatePath, "动态模版页", 3, 1);

            dynamicReport.CreateExcelFile(dataSource);

            // 3.展现报表
            string reportName = "Excel动态报表 Demo";

            return(View("~/Views/Shared/Controls/ExcelReportView.cshtml", new ExcelDisplayViewModel
            {
                Title = reportName,
                FilePhysicalPath = dynamicReport.FilePhysicalPath,
                BodyEndJavascript = "alert('" + reportName + "');",
                BodyStartHtml = string.Format("<a href=\"{0}\" target=\"_blank\">开始下载</a>",
                                              SysContext.CommonService.GetDownloadLink(dynamicReport.FilePhysicalPath, reportName)),
            }));
        }
Ejemplo n.º 2
0
        public ActionResult DynamicExportDemo()
        {
            // 1.获取数据源
            DataSet dataSource = GetDataSourceForDynamicExportDemo();

            // 2.生成报表
            string templatePath = SysContext.Config.ReportTemplateDirectory_Physical + "Excel动态报表模版Demo.xlsx";
            ExcelReport_Dynamic<DynamicExcelDataViewModel> dynamicReport = new ExcelReport_Dynamic<DynamicExcelDataViewModel>(templatePath, "动态模版页", 3, 1);
            dynamicReport.CreateExcelFile(dataSource);

            // 3.展现报表
            string reportName = "Excel动态报表 Demo";
            return View("~/Views/Shared/Controls/ExcelReportView.cshtml", new ExcelDisplayViewModel
            {
                Title = reportName,
                FilePhysicalPath = dynamicReport.FilePhysicalPath,
                BodyEndJavascript = "alert('" + reportName + "');",
                BodyStartHtml = string.Format("<a href=\"{0}\" target=\"_blank\">开始下载</a>",
                        SysContext.CommonService.GetDownloadLink(dynamicReport.FilePhysicalPath, reportName)),
            });
        }