If you convert it to an in memory list first, then you can use group by.
var product = from x in book.Worksheet("FormularyImport").ToList()
group by x.InternalPN into g_pn
select g_pn.First().InternalPN, g_pn.First().Name, g_pn.Sum(x => x.Qty);
foreach (string product in product)
{
//Here I want to iterate through each product, and persist the imported data to the database.
}
Notice the ToList()
call after Worksheet("FormularyImport")