c# - 如何将 devexpress xtra 报告保存在数据库或文件中并从数据库或文件加载它

标签 c# winforms devexpress xtrareport

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

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

有办法做到这一点吗?

环境: C# 4.5 WinForms DevExpress 14.2.4.0

最佳答案

是的,您可以将报告保存到文件或数据库中 使用系统.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

关于c# - 如何将 devexpress xtra 报告保存在数据库或文件中并从数据库或文件加载它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32589450/

相关文章:

c# - 为什么覆盖 .GetHashCode 会清除 WinForms 中的这些数据绑定(bind)值?

wpf - WPF 窗口标题栏上的菜单

c# - AccessType = Offline 在 C# 中的 Google Analytics OAuth

c# - 用于子类化的 NativeWindow 的替代方案

.net - microsoft jet 数据库无法打开文件 '...' 它已经被另一个用户以独占方式打开或者您需要权限才能查看其数据

C#:调整大小时无法更新控件高度

javascript - C# ASP.NET MVC jQuery .html() 函数不适用于 DevExpress 图表数据

c# - 创建编译错误而不是运行时错误

c# - ASP.NET MVC 2 - 组织

c# - SQLDataReader 空到日期时间