I have an application that is accepting two .csv files as input, comparing them using employee Ids and generating two output files in excel format - new employees and removed employees. I am storing the data of input .csv files in hashtables. Storing the data in the following format-
I am then comparing both hashtables and determining what employees are new and what are to be removed. I am storing the final results also in a hashtable.
Now, I am using ClosedXML to generate output excel files. I am converting the output hashtable into a datatable and then printing that datatable on the excel.
Earlier I was printing the output Hashtables in the .csv file but now the requirements have changed so I have to modify the code. The above code is working but it is a bit slow.Is there any other was to do this efficiently. I can have 4000-5000 rows in my output files.
Thank you.
C#:
<key,Value>
<employee ID, Name*City*AccessCode*Role>
I am then comparing both hashtables and determining what employees are new and what are to be removed. I am storing the final results also in a hashtable.
Now, I am using ClosedXML to generate output excel files. I am converting the output hashtable into a datatable and then printing that datatable on the excel.
C#:
Datatable outputTable = new Datatable();
outputTable = ConvertHashtableToDatatable(NewEmployeeHashtable);
using(XLWorkbook wb = new XLWorkbook())
{
var worksheet = wb.Worksheets.Add(outputTable,"Sheet1");
wb.SaveAs(filepath);
}
private Datatable ConvertHashtableToDatatable(Hashtable NewEmployeeHashtable)
{
Datatable table = new DataTable();
table.Columns.Add("EmployeeID", typeof(string))
.
.
.
//adding 10 more columns
foreach(DictionaryEntry entry in NewEmployeeHashtable)
{
string line = entry.Value.ToString();
string[] splittedline = line.Split('*');
DataRow row = table.NewRow();
row["employeeId"] = splittedline[0];
//adding 10 more values in a similar way
table.Rows.Add(row);
}
return table;
}
}
Earlier I was printing the output Hashtables in the .csv file but now the requirements have changed so I have to modify the code. The above code is working but it is a bit slow.Is there any other was to do this efficiently. I can have 4000-5000 rows in my output files.
Thank you.