How to read an excel file in a console application in C #?

1

I am trying to read a data from an excel table in C #, my code looks like this:

            string resp;
            string rota= "D:/Users/e608871/documents/visual studio 2010/Projects/CEMIGID/CEMIGID/CEMIGID.xlsx";
            var excel = new ExcelQueryFactory(rota);
            var res = (from row in excel.Worksheet("Sheet1")
                       let item = new Program
                       {

                           ID = row[0].Cast<string>(),
                           diretorio = row[1].Cast<string>()
                       }
                       select item).ToList();
            excel.Dispose();
            foreach (var item in res)
            {
                resp = item.ID;
            }

But it does not read, it just opens the console and shows nothing

    
asked by anonymous 20.10.2015 / 13:22

1 answer

0

Assuming that the res variable has value, you can display it using the Console's WriteLine method (assuming your application is Console).

foreach (var item in res)
{
   Console.WriteLine(item.ID);
}

Within the foreach you are assigning resp = item.ID to know that you are always overwriting the value of resp , right?

    
20.10.2015 / 13:38