Exporting to PDF, XLS, XLSX, DOCX, CSV and RTF

The Grid View control allows you to export data with ease. Data can be exported to a file or stream in the following formats:

Note that in this demo, export to table formats (XLS, XLSX, and CSV) is performed in the WYSIWYG (What You See Is What You Get) mode. Therefore, the table formatting, e.g., grouping, is lost and grid summaries are converted to strings. However, you can maintain such information by exporting grid data in the data-aware mode.

The buttons in this demo are not built-in to the GridView control and export operations are performed on the server-side button's "Click" handler. You can also use the built-in GridView Toolbar which contains commands for the Export operations.

Export To:

Drag a column header here to group by that column
Product Name Category Supplier Quantity Per Unit Unit Price
ChaiBeveragesExotic Liquids10 boxes x 20 bags$18.00
ChangBeveragesExotic Liquids24 - 12 oz bottles$19.00
Aniseed SyrupCondimentsExotic Liquids12 - 550 ml bottles$10.00
Chef Anton's Cajun SeasoningCondimentsNew Orleans Cajun Delights48 - 6 oz jars$22.00
Chef Anton's Gumbo MixCondimentsNew Orleans Cajun Delights36 boxes$21.00
Grandma's Boysenberry SpreadCondimentsGrandma Kelly's Homestead12 - 8 oz jars$25.00
Uncle Bob's Organic Dried PearsProduceGrandma Kelly's Homestead12 - 1 lb pkgs.$30.00
Northwoods Cranberry SauceCondimentsGrandma Kelly's Homestead12 - 12 oz jars$40.00
Mishi Kobe NikuMeat/PoultryTokyo Traders18 - 500 g pkgs.$97.00
IkuraSeafoodTokyo Traders12 - 200 ml jars$31.00
<dx:BootstrapButton runat="server" Text="PDF" ID="ButtonPDF1" OnClick="ButtonPDF1_Click">
        <CssClasses Icon="fa fa-file-pdf" />
    </dx:BootstrapButton>
    BeginCollapse
    <dx:BootstrapButton runat="server" Text="XLS" ID="ButtonXLS1" OnClick="ButtonXLS1_Click">
        <CssClasses Icon="far fa-file-excel" />
    </dx:BootstrapButton>
    <dx:BootstrapButton runat="server" Text="XLSX" ID="ButtonXLSX1" OnClick="ButtonXLSX1_Click">
        <CssClasses Icon="far fa-file-excel" />
    </dx:BootstrapButton>
    <dx:BootstrapButton runat="server" Text="DOCX" ID="ButtonDOCX1" OnClick="ButtonDOCX1_Click">
        <CssClasses Icon="far fa-file-alt" />
    </dx:BootstrapButton>
    <dx:BootstrapButton runat="server" Text="CSV" ID="ButtonCSV1" OnClick="ButtonCSV1_Click">
        <CssClasses Icon="far fa-file-alt" />
    </dx:BootstrapButton>
    <dx:BootstrapButton runat="server" Text="RTF" ID="ButtonRTF1" OnClick="ButtonRTF1_Click">
        <CssClasses Icon="far fa-file-word" />
    </dx:BootstrapButton>
<dx:BootstrapGridView ID="GridViewExport" runat="server" DataSourceID="DataSource1">
    <Settings ShowGroupPanel="True" />
    <Columns>
        <dx:BootstrapGridViewDataColumn FieldName="ProductName" />
        <dx:BootstrapGridViewDataColumn FieldName="Category" />
        <dx:BootstrapGridViewDataColumn FieldName="Supplier" />
        <dx:BootstrapGridViewDataColumn FieldName="QuantityPerUnit" />
        <dx:BootstrapGridViewTextColumn FieldName="UnitPrice">
<PropertiesTextEdit DisplayFormatString="c" />
        </dx:BootstrapGridViewTextColumn>
    </Columns>
</dx:BootstrapGridView>
protected void ButtonPDF1_Click(object sender, EventArgs e) {
    GridViewExport.ExportPdfToResponse();
}
protected void ButtonXLS1_Click(object sender, EventArgs e) {
    GridViewExport.ExportXlsToResponse(new XlsExportOptions());
}
protected void ButtonXLSX1_Click(object sender, EventArgs e) {
    GridViewExport.ExportXlsxToResponse(new XlsxExportOptions());
}
protected void ButtonCSV1_Click(object sender, EventArgs e) {
    GridViewExport.ExportCsvToResponse(new CsvExportOptions());
}
protected void ButtonDOCX1_Click(object sender, EventArgs e) {
    GridViewExport.ExportDocxToResponse();
}
protected void ButtonRTF1_Click(object sender, EventArgs e) {
    GridViewExport.ExportRtfToResponse();
}

Data Aware Export

The Grid View can export data to XLS and XLSX formats in the data-aware mode. In this mode, the DevExpress Export Engine maintains data grouping layout and automatically transforms summary items to corresponding Excel functions.

Export To:

Order ID Order Date Company Name Shipped Date Ship City Sale Amount
Ship Country: Austria (Continued on the next page)
 1035111/11/2014Ernst Handel11/20/2014 12:00:00 AMGraz$5,445.00
 1035311/13/2014Piccolo und mehr11/25/2014 12:00:00 AMSalzburg$8,603.00
 1038212/13/2014Ernst Handel12/16/2014 12:00:00 AMGraz$2,900.00
 104021/2/2015Ernst Handel1/10/2015 12:00:00 AMGraz$2,695.00
 104301/30/2015Ernst Handel2/3/2015 12:00:00 AMGraz$4,880.00
 105144/22/2015Ernst Handel5/16/2015 12:00:00 AMGraz$8,648.00
 105305/8/2015Piccolo und mehr5/12/2015 12:00:00 AMSalzburg$4,190.00
 105957/10/2015Ernst Handel7/14/2015 12:00:00 AMGraz$4,770.00
 106338/15/2015Ernst Handel8/18/2015 12:00:00 AMGraz$5,483.00
 1069810/9/2015Ernst Handel10/17/2015 12:00:00 AMGraz$3,436.00
 1077612/15/2015Ernst Handel12/18/2015 12:00:00 AMGraz$6,656.00
<dx:BootstrapGridView ID="GridViewExportDataAware" runat="server" DataSourceID="DataSource2">
    <Columns>
        <dx:BootstrapGridViewTextColumn FieldName="OrderID" />
        <dx:BootstrapGridViewDateColumn FieldName="OrderDate" />
        <dx:BootstrapGridViewTextColumn FieldName="ShipCountry" GroupIndex="0" />
        <dx:BootstrapGridViewTextColumn FieldName="CompanyName" />
        <dx:BootstrapGridViewTextColumn FieldName="ShippedDate" />
        <dx:BootstrapGridViewTextColumn FieldName="ShipCity" />
        <dx:BootstrapGridViewTextColumn FieldName="SaleAmount">
            <PropertiesTextEdit DisplayFormatString="c" />
        </dx:BootstrapGridViewTextColumn>
    </Columns>
    <Settings ShowGroupPanel="True" ShowFooter="True" ShowGroupFooter="VisibleIfExpanded" />
    <GroupSummary>
        <dx:ASPxSummaryItem FieldName="OrderID" SummaryType="Count" ShowInGroupFooterColumn="OrderDate" />
        <dx:ASPxSummaryItem FieldName="SaleAmount" SummaryType="Sum" ShowInGroupFooterColumn="SaleAmount" />
    </GroupSummary>
    <TotalSummary>
        <dx:ASPxSummaryItem FieldName="OrderID" SummaryType="Count" ShowInColumn="OrderDate" />
        <dx:ASPxSummaryItem FieldName="SaleAmount" SummaryType="Sum" />
    </TotalSummary>
    <SettingsPager PageSize="12" NumericButtonCount="7"></SettingsPager>
</dx:BootstrapGridView>
protected void ButtonXLS2_Click(object sender, EventArgs e) {
    GridViewExportDataAware.ExportXlsToResponse(new XlsExportOptionsEx() { ExportType = ExportType.DataAware });
}
protected void ButtonXLSX2_Click(object sender, EventArgs e) {
    GridViewExportDataAware.ExportXlsxToResponse(new XlsxExportOptionsEx() { ExportType = ExportType.DataAware });
}

Export Selected Records

To export only the currently selected grid rows, set the Grid View's SettingsExport.ExportSelectedRowsOnly property to true.

Export To:

Product Name Category Supplier Quantity Per Unit Unit Price
ChaiBeveragesExotic Liquids10 boxes x 20 bags$18.00
ChangBeveragesExotic Liquids24 - 12 oz bottles$19.00
Aniseed SyrupCondimentsExotic Liquids12 - 550 ml bottles$10.00
Chef Anton's Cajun SeasoningCondimentsNew Orleans Cajun Delights48 - 6 oz jars$22.00
Chef Anton's Gumbo MixCondimentsNew Orleans Cajun Delights36 boxes$21.00
Grandma's Boysenberry SpreadCondimentsGrandma Kelly's Homestead12 - 8 oz jars$25.00
Uncle Bob's Organic Dried PearsProduceGrandma Kelly's Homestead12 - 1 lb pkgs.$30.00
Northwoods Cranberry SauceCondimentsGrandma Kelly's Homestead12 - 12 oz jars$40.00
Mishi Kobe NikuMeat/PoultryTokyo Traders18 - 500 g pkgs.$97.00
IkuraSeafoodTokyo Traders12 - 200 ml jars$31.00
<dx:BootstrapGridView ID="GridViewExportSelectedRecords" runat="server" DataSourceID="DataSource3" AutoGenerateColumns="False" KeyFieldName="ProductID">
    <SettingsExport ExportSelectedRowsOnly="true"></SettingsExport>
    <Columns>
        <dx:BootstrapGridViewCommandColumn SelectAllCheckboxMode="AllPages" ShowSelectCheckbox="true"></dx:BootstrapGridViewCommandColumn>
        <dx:BootstrapGridViewDataColumn FieldName="ProductName" />
        <dx:BootstrapGridViewDataColumn FieldName="Category" />
        <dx:BootstrapGridViewDataColumn FieldName="Supplier" />
        <dx:BootstrapGridViewDataColumn FieldName="QuantityPerUnit" />
        <dx:BootstrapGridViewTextColumn FieldName="UnitPrice">
            <PropertiesTextEdit DisplayFormatString="c" />
        </dx:BootstrapGridViewTextColumn>
    </Columns>
    <SettingsPager NumericButtonCount="7"></SettingsPager>
</dx:BootstrapGridView>
protected void ButtonRTF3_Click(object sender, EventArgs e) {
    GridViewExportSelectedRecords.ExportRtfToResponse();
}
protected void ButtonCSV3_Click(object sender, EventArgs e) {
    GridViewExportSelectedRecords.ExportCsvToResponse();
}
protected void ButtonXLSX3_Click(object sender, EventArgs e) {
    GridViewExportSelectedRecords.ExportXlsxToResponse();
}
protected void ButtonXLS3_Click(object sender, EventArgs e) {
    GridViewExportSelectedRecords.ExportXlsToResponse();
}
protected void ButtonPDF3_Click(object sender, EventArgs e) {
    GridViewExportSelectedRecords.ExportPdfToResponse();
}

Export with Format Conditions

When data is exported to a PDF or RTF file, the Grid View maintains the style settings applied to the cells (with the exception of images). Moreover, when we export data to Excel formats (XLS and XLSX), the format conditions are transformed to corresponding Excel conditional formatting rules. Therefore, you can manage the rules in Excel after export.

Export To:

Company Name Unit Price Discount Quantity Total
Vins et alcools Chevalier$14.000%12$168.00
Vins et alcools Chevalier$10.000%10$100.00
Vins et alcools Chevalier$35.000%5$175.00
Toms Spezialitäten$19.000%9$171.00
Toms Spezialitäten$42.000%40$1,680.00
Hanari Carnes$8.000%10$80.00
Hanari Carnes$42.0015%35$1,249.50
Hanari Carnes$17.0015%15$216.75
Victuailles en stock$17.005%6$96.90
Victuailles en stock$16.005%15$228.00
<dx:BootstrapGridView ID="GridViewExportWithFormatConditions" runat="server" DataSourceID="DataSource4" KeyFieldName="OrderID;ProductID">
    <Columns>
        <dx:BootstrapGridViewDataColumn FieldName="CompanyName" Width="260px" />
        <dx:BootstrapGridViewTextColumn FieldName="UnitPrice">
            <PropertiesTextEdit DisplayFormatString="c" />
        </dx:BootstrapGridViewTextColumn>
        <dx:BootstrapGridViewSpinEditColumn FieldName="Discount" Settings-FilterMode="Value">
            <PropertiesSpinEdit DisplayFormatString="p0" />
        </dx:BootstrapGridViewSpinEditColumn>
        <dx:BootstrapGridViewDataColumn FieldName="Quantity" />
        <dx:BootstrapGridViewTextColumn FieldName="Total" UnboundType="Decimal" UnboundExpression="UnitPrice * Quantity * (1 - Discount)">
            <PropertiesTextEdit DisplayFormatString="c" />
        </dx:BootstrapGridViewTextColumn>
    </Columns>
    <FormatConditions>
        <dx:GridViewFormatConditionTopBottom FieldName="UnitPrice" Rule="AboveAverage" Format="ItalicText" />
        <dx:GridViewFormatConditionTopBottom FieldName="UnitPrice" Rule="AboveAverage" Format="RedText" />
        <dx:GridViewFormatConditionTopBottom FieldName="Discount" Rule="TopItems" Threshold="15" Format="BoldText" />
        <dx:GridViewFormatConditionHighlight FieldName="Discount" Expression="[Discount] > 0" Format="GreenFillWithDarkGreenText" />
        <dx:GridViewFormatConditionColorScale FieldName="Quantity" Format="GreenWhite" />
        <dx:GridViewFormatConditionIconSet FieldName="Quantity" Format="Ratings4" />
        <dx:GridViewFormatConditionTopBottom FieldName="Total" Rule="TopPercent" Threshold="20" Format="Custom">
            <CellStyle Font-Bold="true" ForeColor="#9c0006" />
        </dx:GridViewFormatConditionTopBottom>
    </FormatConditions>
</dx:BootstrapGridView>
protected void ButtonPDF4_Click(object sender, EventArgs e) {
    GridViewExportWithFormatConditions.ExportPdfToResponse();
}
protected void ButtonXLS4_Click(object sender, EventArgs e) {
    GridViewExportWithFormatConditions.ExportXlsToResponse();
}
protected void ButtonXLSX4_Click(object sender, EventArgs e) {
    GridViewExportWithFormatConditions.ExportXlsxToResponse();
}
protected void ButtonRTF4_Click(object sender, EventArgs e) {
    GridViewExportWithFormatConditions.ExportRtfToResponse();
}
Screen Size
Color Themes
Demo QR Code