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.

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.

    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 ReportsModuleV2.FindReportsModule static method and subscribe to the ReportDataSourceHelper.BeforeShowPreview event.

    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);
    }
    

See Also