Use the CachedReportSource component to export reports that include a large amount of data. This component allows you to avoid memory consumption-related issues by storing pages in a file system or database during document generation.
Create a CachedReportSource instance specifying a report to be exported and a storage to cache the report document.
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
//...
var storage = new MemoryDocumentStorage();
var report = new XtraReport1();
var cachedReportSource = new CachedReportSource(report, storage);
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraPrinting.Caching
'...
Private storage = New MemoryDocumentStorage()
Private report = New XtraReport1()
Private cachedReportSource = New CachedReportSource(report, storage)
The MemoryDocumentStorage object used in this code compactly stores a document in memory. You can use the FileDocumentStorage, DbDocumentStorage or implement a custom storage instead.
To export a report, generate a report document by calling the CreateDocument() method and use the exporting methods the CachedReportSource object's PrintingSystem exposes.
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ...
private void button_Click(object sender, EventArgs e) {
var storage = new MemoryDocumentStorage();
var report = new XtraReport1();
var cachedReportSource = new CachedReportSource(report, storage);
cachedReportSource.CreateDocument();
cachedReportSource.PrinitngSystem.ExportToDocx();
}
Imports System.Windows.Forms
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraPrinting.Caching
' ...
Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim storage = New MemoryDocumentStorage()
Dim report = New XtraReport1()
Dim cachedReportSource = New CachedReportSource(report, storage)
cachedReportSource.CreateDocument()
cachedReportSource.PrinitngSystem.ExportToDocx()
End Sub