Exporting Data from Grid

Exporting Grid Contents

Exporting To a Specific DataTable

To export the Grid contents to a specific DataTable object, please follow the steps below: Add Aspose.Cells.GridDesktop control to your form.

  • Create a specific DataTable object according to your needs.
  • Export the data of a selected Worksheet to your specified DataTable object.

In the example given below, we have created a specific DataTable object having four columns. Finally, we exported worksheet data (starting from the first cell, containing 69 rows and 4 columns) to the DataTable object already created by us.

Example:

Exporting To a New DataTable

Sometimes, developers may not be interested in creating their own DataTable object and might have a simple need to just export the worksheet data to a new DataTable object. It would be the quickest way for developers to export the worksheet data.

In the example given below, we have taken a different approach to demonstrate the usage of the ExportDataTable method. We obtained a reference to the currently active worksheet and then exported the complete data of that worksheet to a new DataTable object. This DataTable object can be used in any way a developer wishes. For example, a developer may bind this DataTable object to a DataGrid to view the data.

Example: