Hi,
with this
Excel C# component you can easily
import Excel to DataTable and then bind it to DataGridView.
Here is a code snippet:
Code:
ExcelFile ef = new ExcelFile();
DataTable dataTable = new DataTable();
// Depending on the format of the input file, you need to change this:
dataTable.Columns.Add("FirstName", typeof(string));
dataTable.Columns.Add("LastName", typeof(string));
// Load Excel file.
ef.LoadXls("FileName.xls");
// Select the first worksheet from the file.
ExcelWorksheet ws = ef.Worksheets[0];
// Extract the data from the worksheet to the DataTable.
// Data is extracted starting at first row and first column for 10 rows or until the first empty row appears.
ws.ExtractToDataTable(dataTable, 10, ExtractDataOptions.StopAtFirstEmptyRow, ws.Rows[0], ws.Columns[0]);
// Bind DataTable to dataGridView
dataGridView.DataSource = dataTable;