This is not an answer to your direct question, but it can solve the problem.
Is getValue in a closed loop? If so, then I will approach him differently. Because Access Cells and Value2 are COM calls, they are slower than regular accessors. If you have a specific range that you are looping, I get an array of the values โโof that range in memory and access the array directly, and not the loop through the cells.
eg. instead
for(int r = 1; r <= 10; r++) for(int c = 1; c <= 20; c++) double val = sheet.Cells[r,c];
make
object[,] values = sheet.Range("A1:J20").Value for(int r = 1; r <= 10; r++) for(int c = 1; c <= 20; c++) double val = values[r,c];
This can fix your problem by removing COM access from the hard loop and fixing any problem giving you weird results.
source share