So I made a simple program, and what it does is read through ExcelOne and collects two pieces of data (Col A and Col B), then compares Col A from ExcelOne to a column in ExcelTwo and where there is a match adds Col A and B from ExcelOne to ExcelTwo - then saves ExcelTwo as a new spreadsheet.
Simple enough.
What has me confused is this...since i am adding the new pieces of data, I insert a new Column A and Column B in ExcelTwo This is because I want to visually check that Column A from ExcelOne matches - it is a QC process.
Here is the code:
So far so simple. Here is my foreach:
Notice something? I am searching Column A, for a match, so that I can write data to Column A.....
This stumped me for about an hour, because I was searching across...Column C....which is where I expected the data to now be, after adding a new Column A and Column B.
My only thought is that because it isn't saved, it is creating a new temporary Excel, which isn't the original excel, and inserting the new columns into that new temp excel, and then writing the data into that new excel, while still reading the original Excel, in its original format.
If you happen to know whether that is right or wrong, or know the right answer, would love to understand what is happening here.
Simple enough.
What has me confused is this...since i am adding the new pieces of data, I insert a new Column A and Column B in ExcelTwo This is because I want to visually check that Column A from ExcelOne matches - it is a QC process.
Here is the code:
C#:
sheet.Columns["A"].Insert();
sheet.Columns["B"].Insert();
sheet.Cells[1, 1] = "File Name";
sheet.Cells[1, 2] = "Data";
So far so simple. Here is my foreach:
C#:
foreach (var data in dict.Keys)
{
for (int k = 1; k <= rowCount; k++)
{
if (xlRange.Cells[k, "A"].Value.ToString() == data)
{
sheet.Cells[k, "B"] = data;
sheet.Cells[k, "A"] = dict[data];
}
}
}
Notice something? I am searching Column A, for a match, so that I can write data to Column A.....
This stumped me for about an hour, because I was searching across...Column C....which is where I expected the data to now be, after adding a new Column A and Column B.
My only thought is that because it isn't saved, it is creating a new temporary Excel, which isn't the original excel, and inserting the new columns into that new temp excel, and then writing the data into that new excel, while still reading the original Excel, in its original format.
If you happen to know whether that is right or wrong, or know the right answer, would love to understand what is happening here.