Get the actual number value of a formule cell

1 Answer 232 Views
SpreadProcessing
Robert
Top achievements
Rank 1
Robert asked on 02 Mar 2022, 01:00 PM | edited on 02 Mar 2022, 01:04 PM

Hi

Is there a way to get the un rounded .Net double value of a formula cell?

Instead of using the GetResultValueAsString method used in the examples:

 

Workbook workbook = new Workbook(); 
Worksheet worksheet = workbook.Worksheets.Add(); 
worksheet.Cells[0, 0].SetValue("=SUM(A2, 3)"); 
worksheet.Cells[1, 0].SetValue(10); 
ICellValue cellValue = worksheet.Cells[0, 0].GetValue().Value; 
CellValueFormat format = worksheet.Cells[0, 0].GetFormat().Value; 
 
string valueAsString = cellValue.GetValueAsString(format); // =SUM(A2, 3) 
string resultValue = cellValue.GetResultValueAsString(format); // 13 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 03 Mar 2022, 07:50 AM

Hi Robert,

You can use the following approach to get the value:

var cellValue = worksheet.Cells[0, 0].GetValue().Value as FormulaCellValue;
var numberValue = cellValue.GetResultValueAsCellValue() as NumberCellValue;
double value = numberValue.Value;
Console.WriteLine(value);

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
SpreadProcessing
Asked by
Robert
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or