The requested page is not available for the requested platform. You are viewing the content for Default platform.

XtraReport.ExportToXls(Stream) Method

Exports a report to the specified stream in XLS format. This method exports data in WYSIWYG mode. Certain controls (e.g., a GridControl) can be exported to XLS(XLSX) format in a faster data-aware export mode, optimized for subsequent analysis of data in MS Excel. To learn how to employ data-aware export, see Export to XLS and XLSX Formats.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v18.2.dll

Declaration

public void ExportToXls(
    Stream stream
)
Public Sub ExportToXls(
    stream As Stream
)

Parameters

Name Type Description
stream Stream

A Stream object to which the created XLS file should be sent.

Remarks

Once the document export has started, it will run until the resulting document is complete and cannot be interrupted or canceled in the process.

Use this method to export a report in XLS format using its current XLS-specific export options. These options are represented by the XlsExportOptions object returned by the ExportOptions.Xls property of a report's XtraReport.ExportOptions. This object provides the XlExportOptionsBase.ShowGridLines, XlExportOptionsBase.TextExportMode and other properties which are intended to specify parameters of the resulting XLS file.

If you want to ignore current export options of a report, and use your specific settings when a report is exported to XLS, you should use the overloaded XtraReport.ExportToXls method with the options parameter.

To learn more, see Export to XLS.

Examples

The following example demonstrates how to export a report to XLS format. To do this, the XtraReport.ExportToXls method should be used. It also demonstrates what specific XlsExportOptions may be used when a report is exported to XLS.

For this example to work, you first need to add a new report (named XtraReport1) to your project, drop some report controls onto it, and then execute the code below (for instance, in the Button.Click event handler of any button on a form). Note also, that if you want the resulting file to be automatically opened in the default program which is used to open *.xls files in your system, you can call the StartProcess method, which is also shown in this example.

using System;
using System.Windows.Forms;
using System.Diagnostics;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
        private void ExportToXLS() {
            // A path to export a report.
            string reportPath = "c:\\Test.xls";

            // Create a report instance.
            XtraReport1 report = new XtraReport1();

            // Get its XLS export options.
            XlsExportOptions xlsOptions = report.ExportOptions.Xls;

            // Set XLS-specific export options.
            xlsOptions.ShowGridLines = true;
            xlsOptions.TextExportMode = TextExportMode.Value;

            // Export the report to XLS.
            report.ExportToXls(reportPath);

            // Show the result.
            StartProcess(reportPath);
        }
        // Use this method if you want to automaically open
        // the created XLS file in the default program.
        public void StartProcess(string path) {
            Process process = new Process();
            try {
                process.StartInfo.FileName = path;
                process.Start();
                process.WaitForInputIdle();
            }
            catch { }
        }
See Also