I can give you some guidance but not readymade code. It is your job = your learninig.
Less effective approach:
1/ read existing excel to datatable, dtSource
2/ create new datatable in newformat, dtDest
loop through all records in dtSource (forEachRow)
3/ transform source row to new format, you could use procedure you described above
4/ add row to dtDest (AddDataRow)
endloop
5/ write dtDest to Excel (WriteRange)
Advanced approach:
The loop and steps 3/ and 4/ can be replaced by LINQ query
There are many resources about it.
Cheers

