read a string from a file in c #?

0

I'm using this code to read a whole line in excel, but I want to read only one cell or a string

        System.IO.StreamReader file = new System.IO.StreamReader(@"c:\Users\Public\TestFolder\Base.xls");



        line = file.ReadLine();
    
asked by Edgar Diaz 17.07.2016 в 19:25
source

1 answer

1

To access an excel file you can not do it with a StreamReader since it will not understand the format of the file, you will have to use a library, I would advise that they be based on open xml like being

ClosedXML - The easy way to OpenXML

To read a cell you would use

 var workbook = new XLWorkbook();
 var ws = workbook.Worksheets.Add("Cell Values");

 string callValue = ws.Cell(2, 2).Value;

Of course I would also advise that you use the excel in xlsx format or in als new versions of excel so it will be compatible with open xml

    
answered by 18.07.2016 в 05:25