I am working on dynamic Excel creation with the help of EPPlus library and I have an excel which data looks like:
Name EmpCode Department attendance
Prashant 111 CSE 70% for Sep
Prashant 111 CSE 90% for Oct
XYZ 112 HR 50% for Sep
XYZ 112 HR 90% for Oct
What I want is: if the current EmpCode is equal to the value of next row then merge this both columns so the expected output will be
I am damn sure that each empCode will be repeated only two times.
The code what I have tried:
for (var rowNum = 1; rowNum <= ws.Dimension.End.Row; rowNum++)
{
var row = ws.Cells[string.Format("{0}:{0}", rowNum)];
}
This code will only work if the empcode is repeated twice but you said you're damn sure it will only be repeated twice so it should be okay, just not very scale-able.
Once you get the data in your spreadsheet you have to loop through all the rows in your dataset. At the beginning of the loop you set the range of your current row and at the end of the loop you set the range of your prior row. If the previous range is set, you evaluate the columns of each row to determine if you should merge the cells together.