Quantcast
Channel: Open XML Format SDK forum
Viewing all articles
Browse latest Browse all 1288

OpenXML not able to get the actual formula text for few cells

$
0
0

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;

                            }
                    }

                }

            }



Viewing all articles
Browse latest Browse all 1288

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>