Can SpreadsheetGear CustomFunction pass in reference to IRange

178 Views Asked by At

I would like to represent the following function in SpreadsheetGear

public static string GetAddress( IRange range )
{
    return range.GetAddress( true, true, ReferenceStyle.A1, true, null );
}

Where I can use this in an Excel file where a cell has a formula of one of the following:

  • =GetAddress(A2),
  • =GetAddress(A2:B3), or
  • =GetAddress(NamedRange)

But I can't figure out how to get a 'IRange reference' from the IArguments parameter of a custom function.

Thanks in advance.

1

There are 1 best solutions below

0
On BEST ANSWER

There is no way to determine what range is being referenced (if any) for an argument that is passed into a custom function. In fact, allowing access to such an IRange object within your custom function would break one of the rules laid out in the Remarks section of our documentation for the Function.Evaluate(...) method:

  • The method must not use any API in the workbook set which is being calculated except for IArguments.CurrentWorksheet.Name, IArguments.CurrentWorksheet.Index or IArguments.CurrentWorksheet.Workbook.Name.