We unload the trend into a pre-prepared book. We don't know the unloading quantity, but it definitely doesn't exceed 999999 lines.
See the example.
In file 4 - the range is clearly defined in the formulas by the length of the unloading.
In file 5 - the maximum range of lines is specified in the formulas.
The data unloading is the same in both files.
The calculation differs greatly in time. I think that the engine should have an algorithm that cuts off ranges that go beyond the used sheet sizes.
PS.Another programmer (ALLIGATOR) on the project helped me find this problem. I asked him to find slow places in the calculations. And the problem described was very much out of the general picture. He said that without fixing this problem there is no point in continuing the search.
The search was performed by this program:
https://forum.lazarus.freepascal.org/index.php/topic,68479.0.html