This is using Microsoft Office Interop.
I have a Dictionary with two data types, one data type matches an entry in a master excel. I am currently using a For loop to loop over the entries, and where there is a match, write the Dictionary data in the two cells to the left. I understand that I am essentially reading over 300+ entries each time but I do not know a better way of identify the connected cell.
The code I have works, but it is quite slow when it comes to writing the data - and I feel there is probably a better way of doing this?
Any tips for speeding this up?
Here is the code I have currently.
I have a Dictionary with two data types, one data type matches an entry in a master excel. I am currently using a For loop to loop over the entries, and where there is a match, write the Dictionary data in the two cells to the left. I understand that I am essentially reading over 300+ entries each time but I do not know a better way of identify the connected cell.
The code I have works, but it is quite slow when it comes to writing the data - and I feel there is probably a better way of doing this?
Any tips for speeding this up?
Here is the code I have currently.
C#:
_Excel.Application excelApp = new _Excel.Application();
_Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath);
_Excel.Worksheet sheet = excelWorkbook.Sheets[1];
_Excel.Range xlRange = sheet.UsedRange;
int colCount = xlRange.Columns.Count;
int rowCount = xlRange.Rows.Count;
sheet.Columns["A"].Insert();
sheet.Columns["B"].Insert();
sheet.Cells[1, 1] = "File Name";
sheet.Cells[1, 2] = "MetaData Verba ID";
var len = dict.Count;
double bar = 100 / len;
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];
}
}
(sender as BackgroundWorker).ReportProgress((int)bar);
bar = bar + 100 / len;
}