我正在开发一个产品应用程序。它是使用 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/