This project has moved. For the latest updates, please go here.

Create a Summary line

Jun 14, 2011 at 2:44 PM
Edited Jun 14, 2011 at 11:19 PM

All,

I want to create a summary line that will total a number of columns after I have called LoadFromCollection. Is this possible for the "Total Row" to have the same style as the range that was just loaded?

I will not know how many rows my range will contain. I want to move to the next row after the range and create my summary row that will Sum a number of columns from beginning at row 9 as this is where my range starts at.

e.g.

var dataRange = ws.Cells["A8"].LoadFromCollection(
                        from r in reportEntity.SettlementReportDetails
                        group r by r.PriceCurrency
                        into p
                        select new
                                   {
                                       PriceCurrency = p.Key,
                                       ExchangeRate = p.Sum(i => i.ExchangeRate),
                                       NoOfTransactions = p.Sum(i=>i.NoOfTransactions),
                                       UnitTotal = p.Sum(i => i.UnitValue),
                                       PriceTotal = p.Sum(i => i.PriceValue),
                                       SettlementTotal = p.Sum(i => i.SettlementValue),
                                   }, true, TableStyles.Light10);

Result:

PriceCurrency ExchangeRate NoOfTransactions UnitTotal PriceTotal SettlementTotal
EUR 1.46505 3 897.48 168.64 247.07
GBP 1.6445 2 909.64 152.6 250.95
AUD 1.07103 1 200.5 51.83 55.51
CAD 1.02571 1 123.56 33.18 34.03
INR 0.02238 1 75.55 926.83 20.74
ZAR 0.14852 1 99.99 185.35 27.53
KWD 3.64724 1 895.32 67.41 245.86
PriceCurrency ExchangeRate NoOfTransactions UnitTotal PriceTotal SettlementTotal
EUR 1.46505 3 897.48 168.64 247.07
GBP 1.6445 2 909.64 152.6 250.95
AUD 1.07103 1 200.5 51.83 55.51
CAD 1.02571 1 123.56 33.18 34.03
INR 0.02238 1 75.55 926.83 20.74
ZAR 0.14852 1 99.99 185.35 27.53
KWD 3.64724 1 895.32 67.41 245.86
Coordinator
Jun 16, 2011 at 6:55 AM

Yes, you need to access the table created when loading...

Use the worksheet.Tables.GetFromRange(dataRange) method (Look at sample 13).

Then add a totals row to the table, like in sample 9.