GemBox Support Forum

Adding Summation Row

I am generating invoices from a SQL Table into Gembox Spreadsheet.

I formatted all the data in the sheet as a table, and I am wanting to add a summary of 2 of the columns in the table. It’s always the same two columns, AA and AB which are the last 2 columns in the sheet.

How do I add a summary line, only summing those 2 columns and adding a row a text of Total? I haven’t seen anything in the examples, or anything online that would help guide me. If there is an example, please point me in that direction.

I tried adding the below, but that’s as far as I can figure out.

var table = xlWorksheet.Tables.Add(oDT.TableName.ToString(), cellRng, true);
table.BuiltInStyle = BuiltInTableStyleName.TableStyleMedium2;
table.HasTotalsRow = true;
table.StyleOptions = TableStyleOptions.BandedRows;

Hi John,

Unfortunately, without having a small demonstration sample from you it’s hard to follow what exactly you want to achieve.

Is it possible for you to send us the output that you currently have and then specify on it what you would like to add?

I presume you want to specify something like this (but I’m not sure):

table.Columns.Last().TotalsRowFunction = TotalsRowFunction.Sum;


Mario, how do I attach the spreadsheet example? Or can I email it to you?

I tried adding the code you suggested, but it doesn’t seem to be correct as the .Last() function isn’t accepted. If I have a way to upload the spreadsheet I will. just trying to do something similar to this


The Last is an extension method from System.Linq.

Anyway, try this:

int count = table.Columns.Count;
table.Columns[count - 1].TotalsRowFunction = TotalsRowFunction.Sum;
table.Columns[count - 2].TotalsRowFunction = TotalsRowFunction.Sum;

Does this solve your issue?


Hi Mario. This worked perfectly, thank you!!