Table of Contents

XlsFile.RecalcRelativeFormula Method

Use this method to know the value of a formula that applies to a cell when the formula is relative. In some places, mostly data validations and names, Excel returns relative formulas.

So for example you might have a name with a definition of "=Sheet1!A2" when you are positioned at cell A1. If you now move the cursor to cell A2 in Excel, the name definition will be "=Sheet1!A3" since the reference is relative to the cell where the cursor is. If you use ExcelFile.RecalcExpression(String) to know the result of the formula, as FlexCel doesn't have a cursor, it will always return the canonical formula as if you were positioned at A1. If you want to know the real formula when you are positioned at A2, you need to call this method with cellRow =3, cellCol = 1 and expression = "=Sheet1!A2". It will return the result of the formula "=Sheet1!A3".

Syntax

Namespace: FlexCel.XlsAdapter

public override Object RecalcRelativeFormula(Int32 activeSheet, Int32 cellRow, Int32 cellCol, String expression)

Parameters

<-> Parameter Type Description
activeSheet Int32 Sheet where you are positioned when doing the calculation. You might pass xls.ActiveSheet here.
cellRow Int32 Row of the cell where the relative formula is.
cellCol Int32 Column of the cell where the relative formula is.
expression String Formula to offset. It must start with "=", and be a valid Excel formula.

Returns

The value of the calculated formula

See also