Export Large Reports
- 2 minutes to read
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);
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();
}