如何序列化DevExpress XtraReport报表设计

我需要序列化报表设计。 这是场景:

该应用程序有基本报告,让我们说“销售报告”,其中包含一组预定义的列和设计,如公司。 标题中的徽标。 用户需要能够更改该布局,例如,添加具有办公室地址或页码的页脚。 为此,他们需要编辑报告,输入设计器并添加/更改他们需要的内容。 此更改的报表布局需要序列化以存储在该用户的数据库中,因此下次用户使用该设计打开该报表。

说得通?

这是我如何做到这一点的简化版本:

XtraReport customReport; customReport = new MyXtraReport(); byte[] layout = LoadCustomLayoutFromDB(); if (layout != null) { using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(layout)) { customReport.LoadLayout(memoryStream); } } using (XRDesignFormEx designer = new XRDesignFormEx()) { MySaveCommandHandler customCommands = new MySaveCommandHandler(designer.DesignPanel); designer.DesignPanel.AddCommandHandler(customCommands); designer.OpenReport(customReport); designer.ShowDialog(this); if (customCommands.ChangesSaved) SaveCustomLayoutToDB(customCommands.Layout); } 

在MySaveCommandHandler类中:

 public virtual void HandleCommand(ReportCommand command, object[] args, ref bool handled) { if (command != ReportCommand.SaveFileAs && command != ReportCommand.SaveFileAs) return; using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) { panel.Report.SaveLayout(memoryStream); this.layout = memoryStream.ToArray(); changesSaved = true; } panel.ReportState = ReportState.Saved; handled = true; } 

我认为你要找的是SaveLayout方法:

保存报告

 YourReport report = new YourReport(); // Save the layout to a file. report.SaveLayout(@"C:\YourReport.repx"); 

加载报告

 YourReport report = new YourReport(); // Load the layout report.LoadLayout(@"C:\YourReport.repx"); 

编辑:

这里是devexpress支持网站的链接 ,解释了如何保存报告定义。

您可以使用Save和LoadLayout覆盖来保存/加载流。 对于设计人员,您可以添加命令处理程序来拦截save命令。

这些文章应涵盖您的需求:

如何:从流中保存和还原报表定义

如何:覆盖最终用户设计器中的命令(自定义保存)

为了完整性: 列出所有操作方法

编辑:固定链接