Share via


StreamReader to read EXCEL?

Question

Friday, October 28, 2011 7:33 PM

Hi there,

Is there a way to read an excel file by using streamreader?

Thanks

All replies (2)

Saturday, October 29, 2011 7:19 AM âś…Answered

You can use ADO.NET to read data from Excel file as if you are reading data from database. Check the below KB article which will guide you on how to read data from excel sheet using OLEDB data provider.

http://support.microsoft.com/kb/302084

http://www.codeproject.com/KB/database/ReadExcel07.aspx

http://sandeep-aparajit.blogspot.com/2008/08/how-to-read-excel-in-c.html

Please mark this post as answer if it solved your problem. Happy Programming!


Friday, October 28, 2011 8:05 PM

Yes it is, if you have a *.csv file.

Use streamreader class, and split line by a delimiter; usually it is  comma.

Example:

using(StreamReader sr = new StreamReader(@"filePath"))
{
      string line;
      string[] columns = null;
      while((line = sr.ReadLine()) != null)
      {
            columns = line.Split(',');
            //now columns array has a ll data of column in a row!
            //like:
            string col1 = columns[0]; //and so on..
      }
}

Mitja