Best way to get a cell value?

I'm writing an xlsx parser and I need to retrieve some numeric cell values.

Values can be a direct input or a formula result.

I found many properties involved in this (ContainsNumber, FormulaValue, FormulaNumberValue, HasFormula, HasFormulaNumberValue, HasNumber, Number, Value, Value2, ...) and I'm a bit confused.

I think I should first check if ContainsNumber is true, then I should check HasFormula/HasNumber and read FormulaNumberValue/Number accordingly.

Is there a better way to read my value without having to worry about the origin of the value (direct input vs formula)?


Thank you, regards

Roberto



1 Reply

RS Ramya Sivakumar Syncfusion Team May 26, 2022 02:03 PM UTC

Hi Roberto,


Greetings from Syncfusion.


The DisplayText is the best way to access the cell value. Kindly use the following code snippet to access the cell values of the Excel file.


Code Snippet:

var value = worksheet.Range["A2"].DisplayText;



Kindly refer to the following link to know more about the Display Text

https://www.syncfusion.com/kb/5822/calculatedvalue-vs-displaytext


Kindly try this and let us if this helps.


Regards,

Ramya.


Loader.
Up arrow icon