Built-in Export
- 3 minutes to read
Note
Supported Versions The information in this topic applies to DevExpress ASP.NET Card View version 17.2 and later.
ASPxCardView data exporting can be implemented using the built-in standard toolbar commands, client-side and server-side API.
Note
Exporting using 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 command including export commands. Specify a standard grid exporting command (listed below) using the CardViewToolbarItem.Command property setting. Refer to the ASPxCardView toolbars topic or Toolbar online demo for more information on using grid toolbars.
- 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>
Exporting API
Execute an appropriate server or client method to implement grid data exporting.
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 customize the exported ASPxCardView elements’ appearance with the ASPxCardView.StylesExport property.
Note
The ASPxCardView cannot export data columns that are hidden or export templates’ content.
Note that templated elements are exported with their default representation. For instance, if you export a card view with templated cells, they are represented as default labels with text in the obtained file.
Excel Data Aware Export
When exporting data in both XLS and XLSX formats, the following card view data is maintained in the resulting excel document:
- Data sorting and filtering - allowing end-users to display relevant data in the desired order.
- Totals summaries - with the ability to modify/change formulas.
- Format conditions - with the ability to modify/change conditional formatting rules.
- Data validation for combo-box columns
- Fixed columns
Export Limitations
- When exporting data to Excel formats, the ASPxCardViewExportSettings.Landscape and ASPxCardViewExportSettings.PaperKind properties are not in effect.
- When exporting data to Excel formats, rich text formatting is ignored in ASPxCardViewExportSettings.ReportHeader and ASPxCardViewExportSettings.ReportFooter property values.
Data Aware Mode Limitations
- The ASPxCardView.StylesExport property has no effect. Use either the CardViewColumn.ExportCellStyle 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 avoid the specified limitations using the WYSIWYG (What You See Is What You Get) export mode. However, table formatting is lost in this mode.
ASPxCardView1.ExportXlsxToResponse(new XlsxExportOptionsEx { ExportType = ExportType.WYSIWYG });
Online Demos
To see the data export in action, refer to the following online 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