Category / Section
How to export data from excel sheet to a datatable?
1 min read
The IWorksheet.ExportDataTable method is used to export data from excel sheet to DataTable. Please refer the below code snippet which illustrates this:
C#
//The first worksheet object in the worksheets collection is accessed. IWorksheet sheet = workbook.Worksheets[0]; //Get as DataTable DataTable datatable = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames); //Upload to dataset DataSet ds = new DataSet(); ds.Tables.Add(datatable);
VB
'The first worksheet object in the worksheets collection is accessed. Dim sheet As IWorksheet = workbook.Worksheets(0) 'Get as DataTable Dim datatable As DataTable = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames) 'Upload to dataset Dim ds As DataSet = New DataSet() ds.Tables.Add(datatable)