We often have a need to give a cell a formula that calculates the weighted average of a group of cells. To do this in excel we would often write a formula that looks like the one you will see in the code example below.
Dim wb As New WorkbookExcel will calculate this correctly but we need it to be calculated correctly with Aspose so that we can save it as an HTML file.
Dim ws As Worksheet = wb.Worksheets(0)
ws.Cells("A1").PutValue("Volume")
ws.Cells("A2").PutValue(6)
ws.Cells("A3").PutValue(-2)
ws.Cells("B1").PutValue("Price")
ws.Cells("B2").PutValue(2.0)
ws.Cells("B3").PutValue(1.0)
ws.Cells("A6").PutValue("Weighted Average Price")
ws.Cells("B6").Formula = "=sumproduct(abs(A2:A3),B2:B3)/sumproduct(abs(A2:A3))"
wb.CalculateFormula()
'Cell B6 where the formula is, now has a value of "#VALUE!"
'The value actually should be "1.75"
Can this be corrected, or is there some other way that we can write this formula to achieve the same result?
Thanks,
-Josh Lupo