【问题标题】:how to save devexpress xtra report in database or file and load it from database or file如何将 devexpress xtra 报告保存在数据库或文件中并从数据库或文件中加载
【发布时间】:2023-03-06 11:15:02
【问题描述】:

我正在开发一个产品应用程序。它是使用 devexpress 控件的 Windows 窗体应用程序。此应用程序是一个计费应用程序。

我的客户想要设计自定义发票格式。如果我在我的 Visual Studio 项目中添加报告,那么我必须将所有报告部署到所有客户端。我想部署专门为客户开发的报告。 为此,我想要一种可以将 Xtrareport 保存为文件或数据库的方法。这样我就可以在运行时动态加载它。

有没有办法做到这一点?

环境: C# 4.5 WinForms DevExpress 14.2.4.0

【问题讨论】:

    标签: c# winforms devexpress xtrareport


    【解决方案1】:

    是的,您可以将报告保存到文件或数据库中 使用 System.IO; 使用 DevExpress.XtraReports.UI; // ...

    // Save a report to a file. 
    private string StoreReportToFile(XtraReport report){
        string path = "C:\\MyReport.repx";
        report.SaveLayout(path);
        return path;
    }
    
    // Save a report to a stream. 
    private MemoryStream StoreReportToStream(XtraReport report){
        MemoryStream stream = new MemoryStream();
        report.SaveLayout(stream);
        return stream;
    }
    

    然后加载它

    using System.IO;
    using DevExpress.XtraReports.UI;
    // ... 
    
    // Load a report from a file. 
    private void LoadReportFromFile(XtraReport report, string filePath){
        if (File.Exists(filePath)) {
            report.LoadLayout(filePath);
        } 
        else {
            Console.WriteLine("The source file does not exist.");
        }
    }
    
    // Load a report from a stream. 
    private void LoadReportFromStream(XtraReport report, MemoryStream stream){
        report.LoadLayout(stream);
    }
    
    // Create a report from a file. 
    private XtraReport CreateReportFromFile(string filePath){
        XtraReport report = XtraReport.FromFile(filePath, true);
        return report;
    }
    
    // Create a report from a stream. 
    private XtraReport CreateReportFromStream(MemoryStream stream){
        XtraReport report = XtraReport.FromStream(stream, true);
        return report;
    }
    

    您可以在这里找到更多信息:https://documentation.devexpress.com/#XtraReports/CustomDocument2592

    【讨论】:

    • 您的回答真的很有帮助。我正在尝试这个并将其设置为答案。
    猜你喜欢
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    相关资源
    最近更新 更多