Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

Could you please help me in the below.
I have below lines of code to group excel column "Issue Type" and sum "value" [img]null[/img]column but actually its not grouping and displaying as it in Excel. and in my first statement if I wont use .ToList() then I will get runtime error as "LinqToExcel does not provide support for Group() Method". Please Help
var grp=from k in excelFile.Worksheet(sheetName).ToList() select k; var grouped = from row in grp group row by row["Issue Type"] into g select new { edd = g.Key, c = g.Sum(row => Convert.ToDouble(row["Time Spent"])) };

foreach (var groupe in grouped) MessageBox.Show("key is" + groupe.edd + " : Sum=" + groupe.c);

and I tried below code as well
int sum = 0;
var grp=from k in excelFile.Worksheet(sheetName).ToList() select k;
var grouped = grp.GroupBy(row => row["Issue Type"]);
foreach (var g in grouped)
{
sum = g.Sum(t => Convert.ToInt32(t["Time Spent"]));
MessageBox.Show("key=" + g.Key + "sum=" + sum);
}


But both behave same.
Posted
Updated 5-Oct-14 18:51pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900