这个示例展示了如何通过 PrintingSystemBase.SaveDocument 方法把报表文档保存到文件,然后如何通过 PrintingSystemBase.LoadDocument 方法加载报表文档。 要查看总说明,请参阅 存储文档。
为了使此示例能正确工作,需执行下列操作。
-
启动 MS Visual Studio (2005、2008 或 2010),并且新建一个或者打开一个现有的 Windows 窗体应用程序。
-
添加新报表 (命名为 XtraReport1) 到应用程序中。
-
把两个按钮拖放到 Form1 (命名为 Button1 和 Button2),并以下列方式接管它们的 Click 事件。
C# | 复制代码 |
---|---|
using System; using System.Windows.Forms; using DevExpress.XtraPrinting; using DevExpress.XtraPrinting.Preview; // ... // A temporary path to save a report to. string filePath = @"C:\Temp\XtraReport1.prnx"; private void button1_Click(object sender, EventArgs e) { // Create a report. XtraReport1 report = new XtraReport1(); // Generate a report document. report.CreateDocument(); // Save a report document to a file. report.PrintingSystem.SaveDocument(filePath); } private void button2_Click(object sender, EventArgs e) { // Create a PrintingSystem instance. PrintingSystem ps = new PrintingSystem(); // Load the document from a file. ps.LoadDocument(filePath); // 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 DevExpress.XtraPrinting Imports DevExpress.XtraPrinting.Preview ' ... ' A temporary path to save a report to. Private filePath As String = "C:\Temp\XtraReport1.prnx" Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _ Handles button1.Click ' Create a report. Dim report As New XtraReport1() ' Generate a report document. report.CreateDocument() ' Save a report document to a file. report.PrintingSystem.SaveDocument(filePath) 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 file. ps.LoadDocument(filePath) ' 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 |