# Export

## Content

The data in the grid can be exported as a delimited text, Excel, HTML, PDF, or RTF file. The following table describes the methods used to export each file type:

| **File Type** | **Method** | **Description** |
| --------- | ------ | ----------- |
| All | [ExportTo](/componentone/docs/win/online-truedbgrid/) | Opens a dialog box in which the user can select the export format. |
| Delimited Text | [ExportToDelimitedFile](/componentone/docs/win/online-truedbgrid/) | Exports the specified rows from the grid to the specified file as delimited text. |
| Excel | [ExportToExcel](/componentone/docs/win/online-truedbgrid/) | Exports the grid to an Excel file. |
| HTML | [ExportToHTML](/componentone/docs/win/online-truedbgrid/) | Exports the grid to an HTML file. |
| PDF | [ExportToPDF](/componentone/docs/win/online-truedbgrid/) | Exports the grid to a PDF file. |
| RTF | [ExportToRTF](/componentone/docs/win/online-truedbgrid/) | Exports the grid to an RTF file. |

>type=note
> **Note**: **TrueDBGrid**'s export and printing features uses the [C1.Win.Printing NuGet package](https://developer.mescius.com/componentone/docs/win/online-printdocument/overview), which provides three libraries: C1.PrintDocument, C1.Win.PrintPreview and C1.Win.RibbonPreview. Each library provides a set of previewing controls or components. The **PrintDocument** library provides the PrintDocument and MultiDocument components, the **PrintPreview** library provides the PreviewOutlineView, PreviewPane, PreviewTextSearchPanel, Thumbnail, PrintPreviewControl and PrintPreviewDialog components, and **RibbonPreview** provides the RibbonPreview and RibbonPreviewDialog components. Since C1Report is now obsolete, make sure that the references for C1Report libraries is replaced by individual library references in the C1.Win.Printing nuget.

### Export to Available File Types

Users can export to available file types by setting the [ExportTo](/componentone/docs/win/online-truedbgrid/) method.

```csharp
this.c1TrueDBGrid1.ExportTo();
```

This topic illustrates the following:

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/print-export-grid-options.png)

Clicking the **Export** button opens the **TrueDBGrid Print/Export Options** dialog box.

1. In the **Action** drop-down list, select the file type, including metafiles and image files.
2. Click the **ellipsis** button next to the **File name** box to open the **Export To** dialog box. Browse to a location to save the file and enter the file name in the **File name** box. Click **OK** to close the **Export To** dialog box.
3. Under **Page Headers and Footers**, add **Header text** and **Footer text**.
<br>
    ![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/print-export-options.png)
4. Click **OK** to export the file.

### Export to Delimited Text

To set the [ExportToDelimitedFile](/componentone/docs/win/online-truedbgrid/) method, add the following code to the **Click** event of the **Export** button:

```csharp
private void button1_Click(object sender, EventArgs e)
        {
            c1TrueDBGrid1.ExportToDelimitedFile(@"c:\temp\composers.csv", C1.Win.C1TrueDBGrid.RowSelectorEnum.AllRows, ",");
        }
```

Clicking the **Export** button creates a delimited text file in the temp directory specified in the code above. Each value in the file is separated by a comma:

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/composers-notepad-snapshot.png)

### Export to Excel

TrueDBGrid allows exporting grid data to Microsoft Excel format by using either of the following methods:

* **SaveExcel** method
* **ExportToExcel** method

It is important to note that time taken to export grid data to Excel format is very small when using the **SaveExcel** method. In comparison, the **ExportToExcel** method takes much longer to export data.

>type=note
> Please note that a reference to the **C1.Win.C1TrueDBGrid.Excel** library is required in order to use **SaveExcel** extension method of the **C1TrueDBGrid** in your project.

To set the **SaveExcel** method, add the following code to the Click event of the Export button:

```csharp
c1TrueDBGrid1.SaveExcel("../../GridData.xlsx");
```

Clicking the **Export** button creates an Excel file as given below:

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/export-excel-1.png)

```csharp
this.c1TrueDBGrid1.SaveExcel("../../GridData.xlsx");
```

To set the **ExportToExcel** method, add the following code to the Click event of the Export button:

```csharp
c1TrueDBGrid1.ExportToExcel(@"c:\temp\composers.xls");
```

```csharp
this.c1TrueDBGrid1.ExportToExcel(@"c:\temp\composers.xls");
```

Clicking the **Export** button creates an Excel file in the temp directory indicated in the code above:

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/export-excel-2.png)

### Export to HTML

To set the [ExportToHTML](/componentone/docs/win/online-truedbgrid/) method, add the following code to the **Click** event of the **Export** button:

```csharp
c1TrueDBGrid1.ExportToHTML(@"c:\temp\composers.html");
```

Clicking the **Export** button creates an HTML file in the temp directory indicated in the code above:

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/htm-snapshot.png)

### Export to PDF

To set the [ExportToPDF](/componentone/docs/win/online-truedbgrid/) method, add the following code to the **Click** event of the **Export** button:

```csharp
c1TrueDBGrid1.ExportToPDF(@"c:\temp\composers.pdf");
```

Clicking the **Export** button creates a PDF file in the temp directory:

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/export-pdf.png)

### Export to RTF

To set the [ExportToRTF](/componentone/docs/win/online-truedbgrid/) method, add the following code to the **Click** event of the **Export** button:

```csharp
c1TrueDBGrid1.ExportToRTF(@"c:\temp\composers.rtf");
```

Clicking the **Export** button creates a RTF file in the temp directory indicated in the code above:

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/export-rtf-grid.png)