windowsforms-7321-controls-and-libraries-printing-exporting-concepts-exporting-export-to-xlsx.md
This help topic outlines the specifics of exporting a document to the XLSX format, introduced by Microsoft in Excel® 2007.
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 |
The XlsxExportOptions class implements export options for XLSX files. Use the report’s ExportOptions.Xlsx property to access these options.
The XlsxExportOptions.ExportMode property specifies how to export the document:
Note
Composite report documents cannot be exported in Single File mode. Do the following to work around this limitation:
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.
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.
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:
Two export modes are available:
Optimized for Excel data analysis, this mode retains data shaping options such as:
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).
Preserves the control’s cell layout, but may not retain all data shaping options.
This is the only mode supported by printing links.
Only non-overlapping controls are exported correctly. Do the following to ensure a valid layout:
XLSX export supports the following hyperlink types:
mailto:.https:// or http://.file:/// (only absolute paths are supported).To maintain cross-references in XLSX, do the following:
Cross-sheet references (in a single workbook) are preserved only when exporting with:
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!.
Use language-specific format codes in XLSX.
// 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.
View Example: Export a Report to XLSX (WinForms)
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);
}
}
}