Import Excel and store in Asp.net DataTable/DataSet

I want to import Excel data and store to asp.net DataTable/DataSet so I can manipulate data and store to SQL Table.


Regards,
Rakesh Patel

Hi Rakesh,


Thank you for contacting Aspose support.

You may use Cells.ExportDataTable method to export a specified range of data into a DataTable to suit your requirements. Please check the below provided code snippet for better elaboration.

C#

//Initialize an instance of Workbook by loading a spreadsheet from disc
var book = new Aspose.Cells.Workbook(myDir + “sample.xlsx”);
//Get the first worksheet
var sheet = book.Worksheets[0];
//Initialize variables to store the range of data on worksheet
int startRow = 0;
int startCol = 0;
int endRow = sheet.Cells.MaxDataRow + 1;
int endCol = sheet.Cells.MaxDataColumn + 1;
//Export data within the specified range
System.Data.DataTable table = sheet.Cells.ExportDataTable(startRow, startCol, endRow, endCol);

In case you face any difficulty, please feel free to write back.