Shailesh Bankar

Shailesh Bankar

  • NA
  • 71
  • 12.9k

Reading .xlsx file in c#

Sep 19 2016 8:44 AM
I'm trying to read .xlsx sheet in c# whose contents are spread over sheet. It's not a single table.Please look at the image -> http://i.stack.imgur.com/aaXxz.png
I've highlighted the things which I want to read separately, in dataTables , if possible.
I've used Following code but it only works when there is only one table is present in the sheet.  
public DataSet ReadXlsx(string filepath)
{   
try 
{ 
   FileStream stream = File.Open(filepath, FileMode.Open, FileAccess.Read);
    //2. Reading from a OpenXml Excel file (2007 format; *.xlsx) 
   IExcelDataReader excelReader2 = ExcelReaderFactory.CreateOpenXmlReader(stream);
    //... //4. DataSet - Create column names from first row
   excelReader2.IsFirstRowAsColumnNames = true; 
   DataSet result2 = excelReader2.AsDataSet(); return result2; 
} 
catch (Exception ex)
 { 
   return null;
 }
}
Please help. Thanks.  

Answers (1)