这个示例展示了如何通过 PrintingSystemBase.SaveDocument 方法把报表文档保存到流中,然后如何通过 PrintingSystemBase.LoadDocument 方法加载它。 要查看总说明,请参阅 存储文档。
为了使此示例能正确工作,需执行下列操作。
-
启动 MS Visual Studio (2005、2008 或 2010),并且新建一个或者打开一个现有的 Windows 窗体应用程序。
-
添加新报表 (命名为 XtraReport1) 到应用程序中。
-
把两个按钮拖放到 Form1 (命名为 Button1 和 Button2),并以下列方式接管它们的 Click 事件。
C# | 复制代码 |
---|---|
using System; using System.Windows.Forms; using System.IO; using DevExpress.XtraPrinting; using DevExpress.XtraPrinting.Preview; //... // Create a MemoryStream instance. MemoryStream stream = new MemoryStream(); private void button1_Click(object sender, EventArgs e) { // Create a report instance. XtraReport1 report = new XtraReport1(); // Generate a report document. report.CreateDocument(); // Save a report document to a stream. report.PrintingSystem.SaveDocument(stream); } private void button2_Click(object sender, EventArgs e) { // Create a PrintingSystem instance. PrintingSystem ps = new PrintingSystem(); // Load the document from a stream. ps.LoadDocument(stream); // Create an instance of the preview dialog. PrintPreviewFormEx preview = new PrintPreviewFormEx(); // Load the report document into it. preview.PrintingSystem = ps; // Show the preview dialog. preview.ShowDialog(); } |
Visual Basic | 复制代码 |
---|---|
Imports System Imports System.Windows.Forms Imports System.IO Imports DevExpress.XtraPrinting Imports DevExpress.XtraPrinting.Preview '... ' Create a MemoryStream instance. Private stream As New MemoryStream() Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _ Handles button1.Click ' Create a report instance. Dim report As New XtraReport1() ' Generate a report document. report.CreateDocument() ' Save a report document to a stream. report.PrintingSystem.SaveDocument(stream) End Sub Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) _ Handles button2.Click ' Create a PrintingSystem instance. Dim ps As New PrintingSystem() ' Load the document from a stream. ps.LoadDocument(stream) ' Create an instance of the preview dialog. Dim preview As New PrintPreviewFormEx() ' Load the report document into it. preview.PrintingSystem = ps ' Show the preview dialog. preview.ShowDialog() End Sub |
Show Me |
---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E211。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。 |