Syncfusion.XlsIO.Base
Example 


Syncfusion.XlsIO Namespace > IWorksheet Interface > ExportDataTable Method : ExportDataTable(IRange,ExcelExportDataTableOptions) Method
Used range of worksheet to be export using IRange Interface.
Export options using ExcelExportDataTableOptions enumeration.

ExportDataTable(IRange,ExcelExportDataTableOptions) Method

Exports worksheet data in the specified range into a System.Data.DataTable.
Syntax
'Declaration
 
Overloads Function ExportDataTable( _
   ByVal dataRange As IRange, _
   ByVal options As ExcelExportDataTableOptions _
) As DataTable
'Usage
 
Dim instance As IWorksheet
Dim dataRange As IRange
Dim options As ExcelExportDataTableOptions
Dim value As DataTable
 
value = instance.ExportDataTable(dataRange, options)

Parameters

dataRange
Used range of worksheet to be export using IRange Interface.
options
Export options using ExcelExportDataTableOptions enumeration.

Return Value

DataTable with worksheet data.
Remarks
This method is not supported in UWP, Xamarin platforms. To know more about ExportDataTable refer this link.
Example
The following code illustrates how to exports worksheet data into a System.Data.DataTable with the specified UsedRange.
using Syncfusion.XlsIO;
using System.Data;
using System.Windows.Forms;
            
public partial class Form1 : Form
{
  public Form1()
  {
    InitializeComponent();
    exportDataInGrid();
  }
  
  public void exportDataInGrid()
  {
    ExcelEngine excelEngine = new ExcelEngine();
    IApplication application = excelEngine.Excel;
    IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic);
    IWorksheet worksheet = workbook.Worksheets[0];
    
    //Import Data From Excel to DataTable
    DataTable customersTable = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames| ExcelExportDataTableOptions.PreserveOleDate);
    
    //Using dataGrid/gridControls you can view the exported DataTable's data
    this.dataGrid1.DataSource = customersTable;
    
    workbook.Close();
    excelEngine.Dispose();
  }
}
AssemblyVersion

Syncfusion.XlsIO.Base: 16.3460.0.29

See Also