I’ve two excel files and I want to extract the difference between them to put in another excel file.
To find the difference I am using a specific reference column from each file to compare.
Using the NPOI library, I stored the data from each excel in two 2d arrays and I was able to find the difference between the two by putting the references columns in unidimensional array and comparing them like below
//copying the values in the references columns to unidimensional arrays
for (int j = 0; j<firstArray.length; j++)
firstArray[j] = firstArray2d[j, 8];
for (int j = 0; j<secondArray.length; j++)
secondArray[j] = secondArray2d[j, 8];
//below I extract the difference between the unidimensional arrays
IEnumerable<string> firstArrayOnly = firstArray.Except(secondArray);
To copy the difference to a new file I was trying to first put it in a third 2d array and then write in an excel but I am having a hard time getting the difference to the third 2d array
I tried the below
string [] diff = new string[firstArrayOnly.Count()];
int cont = 0;
foreach (var n in firstArrayOnly)
{
diff[cont]=n;
cont++;
}
//until here works fine, the problem comes below
string[,] data = new string [firstArrayOnly.Count(),9];
for (int j = 0; j < firstArray2d.GetLength(0); j++)
{
string aux = diff[j];
if (firstArray2d[i,8] == aux)
for (int x = 0; x < firstArray2dGetLength(1); x++)
data[i,x] = firstArray2d[i,j];
}
O keep getting Index Out of bounds