ASP.NET import from Excel – C# and VB samples for ASP.NET

  • Home
  • /
  • Articles
  • /
  • ASP.NET import from Excel – C# and VB samples for ASP.NET

ASP.NET import Excel samples show how to import data from Excel file to dataset in ASP.NET. Use C# or Visual Basic source code below to import from Excel in ASP.NET with Bytescout Spreadsheet SDK.

C#

 const string inputFile = @"PeriodicTableOfElementsSpreadsheet.xls";

           // Open and load excel spreadsheet
           Spreadsheet spreadsheet = new Spreadsheet();
           spreadsheet.LoadFromFile(inputFile);

           // Read the data from the excel spreadsheet into dataset structure 
           DataSet dataSet = spreadsheet.ExportToDataSet();

           // Close the excel spreadsheet object as no need anymore
           spreadsheet.Close();

           // Display data in the first data table in the dataset
           DataTable dt = dataSet.Tables[0];
           // Now this datatable contains data imported from excel file and we 
           // may work with this datatable for further data processing

VB

Dim inputFile As String = "PeriodicTableOfElementsSpreadsheet.xls"

       'Open and load excel spreadsheet
       Dim spreadsheet = New Spreadsheet()
       spreadsheet.LoadFromFile(inputFile)

       ' retrieve the data from the excel spreadsheet and import into aspnet datatable object
       Dim dt As DataTable = spreadsheet.ExportToDataTable()

       'Close the spreadsheet object 
       spreadsheet.Close()

       ' now we may work with this data (imported from excel spreadsheet) stored in "dt" object
prev
next