hey, yes it is the same case. But how do I catch unhandled excepted for this case.
bharathi
public DataTable ExcelToDataTable(string fileName) { try { //open a file and returns a stream FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read); //createxmlreader via xmlreaderfactory IExcelDataReader excelreader = ExcelReaderFactory.CreateOpenXmlReader(stream); //set the first row as column name excelreader.IsFirstRowAsColumnNames = true; //return as dataset DataSet result = excelreader.AsDataSet(); //get all the tables DataTableCollection table = result.Tables; //store it in datatable DataTable resulttable = table["sheet1"]; //return return resulttable; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
Fouad Roumieh
No comments:
Post a Comment