I have an Excel.xls. There are many cells with complex formulas. When I got the results of several formulas, an exception occurred.
var a = wk.GetCreationHelper().CreateFormulaEvaluator();
a.ClearAllCachedResultValues();
var cellv = a.EvaluateInCell(cell);
The evaluation function EvaluateInCell returned IndexOutOfRangeException: Index was outside the bounds of the array.
It is worth noting that the formula in this cell is very long and has multiple levels of nesting. Its formula is this:=IF(SUM(D22:D10000)+SUM(M28:M193)+SUM(M22:M23)+SUM(D22:D10000)+SUM(E22:E10000)*1.2=0,"",SUM(D22:D10000)+SUM(M28:M193)+SUM(M22:M23)+SUM(E22:E10000)*1.2)
First of all, I don't think it is a problem with the formula, because Excel can calculate the result by itself, but it returns an error through Npoi.
I looked through the source code and found that the error may be caused by a negative number in getHashCode. This is my guess, but I still don't know how to solve this problem. The source code is as follows
int startIx = cce.GetHashCode() % arr.Length;
for (int i = startIx; i < arr.Length; i++)
{
CellCacheEntry item = arr[i];
if (item == cce)
{
// already present
return false;
}
if (item == null)
{
arr[i] = cce;
return true;
}
}
for (int i = 0; i < startIx; i++)
{
CellCacheEntry item = arr[i];
if (item == cce)
{
// already present
return false;
}
if (item == null)
{
arr[i] = cce;
return true;
}
}