@alex-rkn
For your trouble, we think you are using ReferredArea.GetValue()/GetValues() in the implementation of ICustomFunction or AbstractCalculationEngine. When there are formulas in the referred area and the formulas have not been calculated, then the formulas will be calculated before returning their values.
Two ways can be used to avoid the calculation for those referred formulas:
1 - You may get the cell values in the referred area manually by yourself.
CalculationOptions copts = new CalculationOptions();
copts.CustomEngine = new MyEngineForReferredArea1(wb);
//------------------------------------------
//------------------------------------------
//------------------------------------------
private class MyEngineForReferredArea1 : AbstractCalculationEngine
{
private Workbook _wb;
internal MyEngineForReferredArea1(Workbook wb)
{
_wb = wb;
}
public override void Calculate(CalculationData data)
{
object p = data.GetParamValue(0);
if (p is ReferredArea)
{
ProcessReference((ReferredArea)p);
}
data.CalculatedValue = "Success";
}
private void ProcessReference(ReferredArea ra)
{
if (ra.IsExternalLink)
{
Console.WriteLine("External link is not supported.");
return;
}
Cells cells = _wb.Worksheets[ra.SheetName].Cells;
int startRow = ra.StartRow;
int startCol = ra.StartColumn;
int endRow = ra.EndRow;
int endCol = ra.EndColumn;
for (int i = startRow; i <= endRow; i++)
{
for (int j = startCol; j <= endCol; j++)
{
Cell cell = cells.CheckCell(i, j);
if (cell == null)
{
Console.WriteLine(CellsHelper.CellIndexToName(i, j) + ": null");
}
else
{
Console.WriteLine(cell.Name + ": " + cell.Value);
}
}
}
}//-----ProcessReference
}
2 - Set the Recursive flag to false when fetching values of the referred area:
CalculationOptions copts = new CalculationOptions();
copts.CustomEngine = new MyEngineForReferredArea2(copts);
//------------------------------------------
//------------------------------------------
//------------------------------------------
private class MyEngineForReferredArea2 : AbstractCalculationEngine
{
private CalculationOptions _copts;
internal MyEngineForReferredArea2(CalculationOptions copts)
{
_copts = copts;
}
public override void Calculate(CalculationData data)
{
object p = data.GetParamValue(0);
if (p is ReferredArea)
{
if (_copts != null && _copts.Recursive)
{
_copts.Recursive = false;
try
{
ProcessReference((ReferredArea)p);
}
finally
{
_copts.Recursive = true;
}
}
else
{
ProcessReference((ReferredArea)p);
}
}
data.CalculatedValue = "Success";
}//-----Calculate
private void ProcessReference(ReferredArea ra)
{
object vs = ra.GetValues();
if (vs is Array)
{
object[][] avs = (object[][])vs;
foreach (object[] rd in avs)
{
foreach (object v in rd)
{
Console.WriteLine(_copts == null ? "default:" + v : "norecursive: " + v);
}
}
}
}//-----ProcessReference
}