Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
815
Cannot Get Value From A Cell Containing A Formula
posted

I have an excel spreadsheet that I am creating from scratch using the Infragistics.Excel library version 16.1.20161.2044. After I create the spreadsheet, the user can then recall values from the spreadsheet using the following code:

' get the workbook
Dim QuoteWB As Workbook = Workbook.Load("My_Workbook.xlsx")

' get the desired worksheet
Dim CensusWS As Worksheet = QuoteWB.Worksheets("Census")

' the formula for cell D4 looks something like this:
' =('Worksheet1'!C3+'Worksheet1'!D3)*12
Dim AnnualSalary As String = CensusWS.GetCell("D4").Value

The first worksheet in my workbook consists of raw values (no formulas). I am able to get values from this worksheet without any problems. All subsequent worksheets have formulas that are referencing the original worksheet. I am only able to get the value from a cell that does not contain a formula. Any cell that has plain text will work just fine, but as soon as I try to get the value from a cell that has a formula, I get the following error message:

System.InvalidCastException: Conversion from type 'ErrorValue' to type 'String' is not valid.

My goal is to get the value from a cell that contains a formula. I have implemented some complex formulas in the workbook and I need a way to retrieve the results.

Parents
No Data
Reply
  • 435
    posted

    Hello Jack,

    Thank you for using our community!

    I have investigated you case and you could get both the value and the formula. My suggestion is to get the target cell by using the following code:

    Dim cellvalueRef As WorksheetCell = ws.Rows(4).Cells(49)

    “cellvalueRef” is a cell which contains a formula. I am attaching a screenshot with the properties of the worksheetCell. You could get the value of “cellvalueRef” by using its value property.

    You could test my suggestion on your side and if it’s not working for you, please send me an isolated code sample in order to be on the same page regarding this issue.

    Let me know if I may be of further assistance.

    Regards,

    Aneta Gicheva,

    Infragistics

Children