How to: Customize the Report Export Options 操作:自定义报表导出选项

This example demonstrates how to access the ExportOptions object, which stores the document export options for different formats. These options are applied when you export a report from a Report Viewer in both WinForms and ASP.NET applications.

此示例演示如何访问 ExportOptions 对象,该对象存储不同格式的文档导出选项。当您在 WinForms 和ASP.NET应用程序中从报表查看器导出报表时,将应用这些选项。

 

Note 注意
Mobile applications do not support the document export options, so the approach described in this topic cannot be implemented in the Mobile platform.
移动应用程序不支持文档导出选项,因此本主题中描述的方法无法在移动平台中实现。

 

In this topic, it is assumed that you have an XAF application that uses the Reports V2 Module, and you have created one or more reports (see Reports V2 Module Overview).

  • In the platform-agnostic module, declare the following helper class.

在本主题中,假定您有一个使用报表 V2 模块的 XAF 应用程序,并且您创建了一个或多个报表(请参阅报表 V2 模块概述)。

  • 在与平台无关的模块中,声明以下帮助器类。

    using DevExpress.XtraPrinting;
    // ...
    public static class ExportConfigurator {
        public static void Setup(ExportOptions exportOptions) {
            SetHtmlOptions(exportOptions.Html);
            SetPdfOptions(exportOptions.Pdf);
            SetXlsOptions(exportOptions.Xls);
        }
        private static void SetXlsOptions(XlsExportOptions xlsExportOptions) {
            // XLS-specific options: 
            xlsExportOptions.SheetName = "CustomXlsSheetTitle";
            xlsExportOptions.ShowGridLines = true;
        }
        private static void SetPdfOptions(PdfExportOptions pdfExportOptions) {
            // PDF-specific options: 
            pdfExportOptions.DocumentOptions.Title = "CustomPdfTitle";
            pdfExportOptions.ImageQuality = PdfJpegImageQuality.Medium;
        }
        private static void SetHtmlOptions(HtmlExportOptions htmlExportOptions) {
            // HTML-specific options: 
            htmlExportOptions.Title = "CustomHtmlTitle";
            htmlExportOptions.ExportMode = HtmlExportMode.SingleFilePageByPage;
            htmlExportOptions.PageBorderColor = System.Drawing.Color.Gray;
            htmlExportOptions.EmbedImagesInHTML = true;
        }
    }

     

  • In the Module.cs (Module.vb) file, override the ModuleBase.Setup method, find the ReportsModuleV2 instance using the static ReportsModuleV2.FindReportsModule method and subscribe to the ReportDataSourceHelper.BeforeShowPreview event.

  • 在Module.cs(module.vb)文件中,重写ModuleBase.安装程序方法,使用静态报表模块V2.FindReportsModule方法查找报表模块V2实例,并订阅"报表数据源帮助程序.前显示预览"事件。

    using DevExpress.ExpressApp.ReportsV2;
    // ...
    public override void Setup(ApplicationModulesManager moduleManager) {
        base.Setup(moduleManager);
        ReportsModuleV2 reportsModule = ReportsModuleV2.FindReportsModule(moduleManager.Modules);
        if(reportsModule != null) {
            reportsModule.ReportsDataSourceHelper.BeforeShowPreview += ReportsDataSourceHelper_BeforeShowPreview;
        }
    }

     

  • In the event handler, execute the ExportConfigurator.Setup static helper method implemented in the first step.

  • 在事件处理程序中,执行导出配置器.设置在第一步中实现的静态帮助器方法。

    private void ReportsDataSourceHelper_BeforeShowPreview(object sender, BeforeShowPreviewEventArgs e) {
        ExportConfigurator.Setup(e.Report.ExportOptions);
    }

     

posted @ 2020-01-08 15:56  code first life  阅读(561)  评论(0编辑  收藏  举报