We are using openxml nuget package DocumentFormat.OpenXml to read excel cell values. Our requirement is to read the actual formula text from a cell using "cell.CellFormula" property,but for few of the cells we are getting the actual value instead of formula.
Ex:Say the cell(A10) has the formula : =A5+1 AND A5 has value of "2".
our intention is to read the formula in A10 which is "=A5+1" but instead we are getting the value as "2"
using (var document = SpreadsheetDocument.Open(filePath, false)) { var workbookPart = document.WorkbookPart; var workbook = workbookPart.Workbook; var sheets = workbook.Descendants<Sheet>(); foreach (var sheet in sheets) { var worksheetPart = (WorksheetPart)workbookPart.GetPartById(sheet.Id); var cells = worksheetPart.Worksheet.Descendants<Cell>(); foreach (var cell in cells) { if (cell.CellFormula != null || cell.CellValue != null || cell.DataType != null) { string cellFormula=cell.CellFormula; } } } }
↧
OpenXML not able to get the actual formula text for few cells
↧