Skip to main content

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Export to XLSX

  • 5 minutes to read

This help topic outlines the specifics of exporting a document to the XLSX format, introduced by Microsoft in Excel® 2007.

#XLSX Format Overview

The XLSX format supports significantly more rows and columns than the XLS format:

XLSX XLS
16,384 columns 256 columns
1,048,576 rows 65,536 rows

#Export Options

The XlsxExportOptions class implements export options for XLSX files. Use the report’s ExportOptions.Xlsx property to access these options.

#File Options

The XlsxExportOptions.ExportMode property specifies how to export the document:

  • Single File: The document is exported as a single sheet with the page header and footer.
  • Single File Page by Page: Each page is exported as a separate sheet within a single XLSX file. Sheet names are generated based on the XlExportOptionsBase.SheetName property.
  • Different Files: The document is exported to multiple files, page-by-page. Each page is exported to a single XLSX file.

Note

Composite report documents cannot be exported in Single File mode. Do the following to work around this limitation:

  • Use sub reports to combine multiple reports into a single document.
  • Export reports separately and then combine them manually.

#Handle Large Text

If a control’s XRControl.Text property exceeds 32,767 characters, Excel truncates the remaining text without warning. Refer to the following article for additional information: Excel specifications and limits.

#Encryption Options

Use the XlExportOptionsBase.EncryptionOptions property to access XLS/XLSX encryption options. To encrypt an XLSX file, set the EncryptionOptions.Password property. The default empty password cannot be used for file encryption.

Important

Excel passwords are saved with report definitions in plain text. Ensure only trusted users have access to report definition files.

#Supported Encryption Types

Use the XlEncryptionOptions.Type property to specify the encryption type:

Encryption is supported for both WYSIWYG and DataAware export modes.

Do the following to configure Excel’s print settings:

#Data Shaping Options

Two export modes are available:

#Data-Aware Export

Optimized for Excel data analysis, this mode retains data shaping options such as:

  • Native Excel grouping, sorting, and filtering
  • Excel formulas

Note

This mode is not supported by printing links in WinForms and WPF applications. Instead, call export methods of specific controls (for example, WinForms Data Grid).

#WYSIWYG Export

Preserves the control’s cell layout, but may not retain all data shaping options.

This is the only mode supported by printing links.

#Document Content Options

#Document Layout Considerations

Only non-overlapping controls are exported correctly. Do the following to ensure a valid layout:

  1. Enable the DesignerOptions.ShowExportWarnings property at design time.
  2. Verify that intersecting controls (marked in red) exist.

ShowExportWarnings

XLSX export supports the following hyperlink types:

  • Email: URLs must start with mailto:.
  • Web Page: URLs must start with https:// or http://.
  • File: URLs must start with file:/// (only absolute paths are supported).

#Cross-Reference Support

To maintain cross-references in XLSX, do the following:

  • Cross-references must be one-to-one or many-to-one.
  • Referencing elements must have identical, unique anchors.
  • A brick containing a reference must have an assigned URL.
  • The target brick must have a defined Brick.AnchorName property.

Cross-sheet references (in a single workbook) are preserved only when exporting with:

#Data Format Options

The XlExportOptionsBase.TextExportMode property specifies whether exported content retains the formatting of the source document. Export modes include:

Note

Custom types are not exported, and affected cells display #VALUE!.

#Locale-Specific Formatting

Use language-specific format codes in XLSX.

C#
// German locale with Euro sign
myLabel.XlsxFormatString = "[$€;-0407] 0.00";

Refer to the following topic in MSDN for more information: Language Identifier Constants and Strings.

#Example: Export a Report to XLSX (WinForms)

View Example: Export a Report to XLSX (WinForms)

C#
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using System.Windows.Forms;
using System;

namespace XlsxExportExample {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e) {
            // Create a report
            XtraReport report = new XtraReport() {
                Name = "Report Example",
                Bands = {
                    new DetailBand() {
                        Controls = {
                            new XRLabel() {
                                Text = "Some content goes here...",
                            }
                        }
                    }
                }
            };

            // Specify export options
            XlsxExportOptions xlsxExportOptions = new XlsxExportOptions() {
                ExportMode = XlsxExportMode.SingleFile,
                ShowGridLines = true,
                FitToPrintedPageHeight = true
            };

            // Specify the path for the exported XLSX file
            string xlsxExportFileName =
                Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) +
                @"\Downloads\" +
                report.Name +
                ".xlsx";

            // Export the report
            report.ExportToXlsx(xlsxExportFileName, xlsxExportOptions);
            System.Diagnostics.Process.Start(xlsxExportFileName);
        }
    }
}