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 @   code first life  阅读(567)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2015-01-08 CSharp Similarities and Differences
2015-01-08 Nemerle Quick Guide
点击右上角即可分享
微信分享提示