Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
We know that a spreadsheet stores data as a sequence of rows and columns. If all values in the columns of a worksheet are strongly typed (which means all values in a column must have the same data type), then we can export the worksheet content by calling the ExportDataTable method of the Cells class. The ExportDataTable method takes the following parameters to export worksheet data as a DataTable object:
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(FOD_OpenFile.FileName, FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Exporting the contents of 2 rows and 2 columns starting from the first cell to a DataTable
DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, 2, 2, true);
// Binding the DataTable with a DataGrid
dataGridView1.DataSource = dataTable;
// Closing the file stream to free all resources
fstream.Close();
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.