How to: Export a Chart to XLS
The following example demonstrates how to export a chart image inserted into XLS document to either a file or a stream.
Add a ChartControl object and populate it with data.
The Chart Control uses the DevExpress Printing Library to export a chart image. Add references to the following assemblies:
- DevExpress.XtraPrinting.19.1
- DevExpress.Printing.v19.1.Core
Use the ChartControl.IsPrintingAvailable property to check whether the chart can be exported.
To export the chart in the XLS format, use the ChartControl.ExportToXls method.
using System.IO;
// ...
if (chartControl1.IsPrintingAvailable){
// Exports to an XLS file.
chartControl1.ExportToXls("Output.xls");
// Exports to a stream as XLS.
FileStream xlsStream = new FileStream("Output.xls", FileMode.Create);
chartControl1.ExportToXls(xlsStream);
// ...
xlsStream.Close();
}