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:
- XlEncryptionType.Strong (the default value): Uses Agile Encryption.
- XlEncryptionType.Compatible: Uses Standard Encryption (compatible with Excel 2007).
Encryption is supported for both WYSIWYG and DataAware export modes.
#Print Options
Do the following to configure Excel’s print settings:
- Fit All Columns on One Page: Sets the XlExportOptionsBase.FitToPrintedPageHeight property to true. This option is available in an Excel document’s Print dialog.
- Fit All Rows on One Page: Sets the XlExportOptionsBase.FitToPrintedPageWidth property to true. This option is available in an Excel document’s Print dialog.
- Fit Sheet on One Page: Enables both options above.
#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 Win
#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
- Raw Data Export: Enable the XlExportOptionsBase.RawDataMode option to export only report data (ignoring images, styles, etc.).
- Image Rasterization: Use the RasterizeImages property to enable image rasterization (convert vector graphics into raster images). The RasterizationResolution property controls resolution.
#Document Layout Considerations
Only non-overlapping controls are exported correctly. Do the following to ensure a valid layout:
- Enable the DesignerOptions.ShowExportWarnings property at design time.
- Verify that intersecting controls (marked in red) exist.
#Hyperlink Support
XLSX export supports the following hyperlink types:
- Email: URLs must start with
mailto:
. - Web Page: URLs must start with
https://
orhttp://
. - 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:
- Text: All data is exported as strings. The XRControl.XlsxFormatString property is ignored.
- Value: Preserves both .NET and native XLSX formats. You can use the XRControl.XlsxFormatString property to specify an XLSX format string.
Note
Custom types are not exported, and affected cells display #VALUE!.
#Locale-Specific Formatting
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.
#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);
}
}
}