Built-in Export
- 3 minutes to read
Note
Supported Versions: The information in this topic applies to DevExpress ASP.NET Card View v17.2 and later.
You can use the built-in standard toolbar commands and client-side/server-side API to export ASPxCardView data.
Note
Export with the built-in toolbar commands and client-side API is disabled by default due to possible security issues. To enable this functionality, set the ASPxGridExportSettings.EnableClientSideExportAPI property to true
.
Standard Toolbar Commands
The ASPxCardView toolbar provides frequently used grid commands that include export commands. Use the CardViewToolbarItem.Command property setting to specify a standard grid export command (listed below). See the following help topic for more information on how to use grid toolbars: ASPxCardView toolbars. You can also refer to the following DevExpress ASP.NET Card View demo: Toolbar.
- CardViewToolbarCommand.ExportToPdf
- CardViewToolbarCommand.ExportToRtf
- CardViewToolbarCommand.ExportToCsv
- CardViewToolbarCommand.ExportToXls
- CardViewToolbarCommand.ExportToXlsx
- CardViewToolbarCommand.ExportToDocx
<dx:ASPxCardView ID="CardView" runat="server" KeyFieldName="ProductID" DataSourceID="ProductsDataSource" Width="100%"> <Toolbars> <dx:CardViewToolbar EnableAdaptivity="true"> <Items> <dx:CardViewToolbarItem Command="ExportToXls" /> <dx:CardViewToolbarItem Command="ExportToXlsx" /> <dx:CardViewToolbarItem Command="ExportToRtf" /> </Items> </dx:CardViewToolbar> </Toolbars> <Columns> ... </Columns> </dx:ASPxCardView>
Export API
Execute the corresponding client or server method (based on the export format) to implement grid data export.
The following examples illustrate how to use client and server exporting methods:
Client API
<dx:ASPxCardView ID="ASPxCardView1" ClientInstanceName="cardView" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" KeyFieldName="ProductID"> <SettingsExport EnableClientSideExportAPI="true"></SettingsExport> <Columns> ... </Columns> </dx:ASPxCardView> <br /> <dx:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" Text="Export"> <ClientSideEvents Click="function(s, e) { cardView.ExportTo(ASPxClientCardViewExportFormat.Xls); }" /> </dx:ASPxButton>
Server API
switch(e.Item.Name) { case "CustomExportToXLS": CardView.ExportXlsToResponse(new DevExpress.XtraPrinting.XlsExportOptionsEx { ExportType = ExportType.WYSIWYG }); break; case "CustomExportToXLSX": CardView.ExportXlsxToResponse(new DevExpress.XtraPrinting.XlsxExportOptionsEx { ExportType = ExportType.WYSIWYG }); break; default: break; }
You can use the ASPxCardView.StylesExport property to customize the exported ASPxCardView element appearance.
Note
ASPxCardView cannot export template content or data columns that are hidden.
Note that templated elements are exported with their default display settings. For instance, if you export a card view with templated cells, they are displayed with default text labels in the exported file.
Excel Data Aware Export
When you export data in XLS and XLSX formats, the following is included in the exported Excel document:
- Data sorting and filtering - allow end users to display relevant data in the desired order.
- Totals summaries - enable users to modify formulas.
- Format conditions - allow users to change conditional formatting rules.
- Data validation for combo-box columns
- Fixed columns
Export Limitations
Note that when you export data to Excel formats, the following limitations apply:
- The ASPxCardViewExportSettings.Landscape and ASPxCardViewExportSettings.PaperKind properties are not in effect.
- The ASPxCardViewExportSettings.ReportHeader and ASPxCardViewExportSettings.ReportFooter property values ignore rich text formatting.
Data Aware Mode Limitations
- The ASPxCardView.StylesExport property has no effect. Use either the CardViewColumn.ExportCellStyle property at the column level or the XlsExportOptionsEx.CustomizeCell / XlsxExportOptionsEx.CustomizeCell event instead.
- The ASPxCardViewExportSettings.ReportHeader and ASPxCardViewExportSettings.ReportFooter properties are not in effect.
- The ASPxCardView.ExportRenderBrick event does not fire. You can use the XlsExportOptionsEx.CustomizeCell or XlsxExportOptionsEx.CustomizeCell event instead.
You can use the WYSIWYG (What You See Is What You Get) export mode to avoid these limitations. Note, however, that table formatting is lost in this mode.
ASPxCardView1.ExportXlsxToResponse(new XlsxExportOptionsEx { ExportType = ExportType.WYSIWYG });
Online Demos
To see the data export feature in action, refer to the following DevExpress ASP.NET Card View demos:
Exporting to Different Formats
Task-Based Help
- How to: Export ASPxCardView Data as a PDF
- How to: Draw Columns in an Exported Document
- How to: Export Only Selected Cards
- How to: Export Images from a Column of the CardViewImageColumn Type