Search code examples
c#excellinqlinq-to-excel

LinqToExcel Is it possible to read the formula as a string


I've encountered a problem. I'm trying to read data from xlsx document using LinqToExcel. The data is retrieved but the document has cells which are interpreted as formulas with text like "=- Something". Is it possible to get those cells text and not the counted value of the formula?

var book = new LinqToExcel.ExcelQueryFactory(path);
var worksheetNames = book.GetWorksheetNames();

var query =           
    from row in book.WorksheetNoHeader()
    where row[0] != ""
    select row;

Solution

  • With LinqToExcel you can't receive formula, because linqtoExcel uses OleDB to access sheet. OleDB doesn't allow to access formulas. Instead linqtoExcel you can use Worksheet.Range Property

    Example:

    Range range = (Range)sheet.Cells[i, j];
    return range.Formula;