I have tried to implement code suggested by you and its giving me error.
Below is the code.
protected DataTable ToDataTable(string filepath, string sheetName, string whereClause)
{
DataTable dt = new DataTable();
dt.Columns.Add(“Pop Code”, typeof(string));
dt.Columns.Add(“Bulked”, typeof(string));
dt.Columns.Add(“Exer Type”, typeof(string));
dt.Columns.Add(“Optionee ID”, typeof(string));
dt.Columns.Add(“Optionee ID”, typeof(string));
dt.Columns.Add(“First Name”, typeof(string));
dt.Columns.Add(“Last Name”, typeof(string));
dt.Columns.Add(“Tax Code”, typeof(string));
dt.Columns.Add(“Plan Id”, typeof(string));
dt.Columns.Add(“Grant Date”, typeof(string));
dt.Columns.Add(“Grant Type”, typeof(string));
dt.Columns.Add(“Grant Price”, typeof(string));
dt.Columns.Add(“Shares Granted”, typeof(string));
dt.Columns.Add(“Exercise Fmv”, typeof(string));
dt.Columns.Add(“Options Exercised”, typeof(string));
dt.Columns.Add(“Sale Price”, typeof(string));
dt.Columns.Add(“SharesSold”, typeof(string));
dt.Columns.Add(“ShareProceeds”, typeof(string));
dt.Columns.Add(“Commissions”, typeof(string));
dt.Columns.Add(“SEC Fee”, typeof(string));
dt.Columns.Add(“Grant Code 1”, typeof(string));
dt.Columns.Add(“Grant Text 1”, typeof(string));
dt.Columns.Add(“Grant Text 2”, typeof(string));
dt.Columns.Add(“Exercise Id”, typeof(string));
dt.Columns.Add(“Exercise Date”, typeof(string));
dt.Columns.Add(“Options Exercised1”, typeof(string));
dt.Columns.Add(“Shares Outstanding”, typeof(string));
dt.Columns.Add(“Vest ID”, typeof(string));
dt.Columns.Add(“Ytd Supplemental Income”, typeof(string));
dt.Columns.Add(“YTD FICA”, typeof(string));
dt.Columns.Add(“User Text 4”, typeof(string));
dt.Columns.Add(“Term Id”, typeof(string));
dt.Columns.Add(“Term date”, typeof(string));
dt.Columns.Add(“Shares Exercisable”, typeof(string));
int startRow = 0;
string range = string.Empty;
//Header for data is at 5th row
range = “A5:AG”;
startRow = 4;
//Instantiate License class and call its SetLicense method to use the license
var lic = new License();
lic.SetLicense(“EYSMS.Gateway.Aspose.Cells.lic”);
//Creating a file stream containing the Excel file to be opened
FileStream fstream = File.OpenRead(filepath); //new FileStream(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[sheetName];
//Exporting the contents of rows and columns starting from 1st cell to DataTable
DataTable datatable= worksheet.Cells.ExportDataTable(dt, 1, 0, worksheet.Cells.MaxDataRow + 1, false);
//Closing the file stream to free all resources
fstream.Close();
//Applying filter criteria.
if (!string.IsNullOrEmpty(whereClause))
{
DataView dvData = new DataView(dt);
dvData.RowFilter = whereClause;
dt = dvData.ToTable();
}
return dt;
}
And Error message is : Cannot implicitly convert type ‘void’ to System.Data.DataTable.
Kindly look into that.