Quantcast
Channel: npoi Discussions Rss Feed
Viewing all articles
Browse latest Browse all 637

New Post: How to read cell text when formula is attached to cell.

$
0
0
In that case you can go with 2 options, or either use the ICell.CachedFormulaResultType which gives you the CellType of the actual result of that Formula and then parse that or you can go with Workbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateInCell(ICell) which basically evaluates the formula and replaces that with the ACTUAL Value in the cell.

If you go with the first approach, you can create an extension method and do something like :
public static object GetValue(this ICell cell, CellType cellType)
        {
            object value = null;

            switch (cellType)
            {
                case CellType.STRING:
                {
                    value = cell.StringCellValue;
                    break;
                }
                case CellType.FORMULA:
                {   //If its a Formula, get the Actual Value not the formula itself.
                    value = cell.GetValue(cell.CachedFormulaResultType);
                    break;
                }
---- rest of code

Viewing all articles
Browse latest Browse all 637

Trending Articles



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