I'm trying to get the subtotals for a table in C# using Microsoft.Interop.Excel, and there is a built in function for that.
[Here][1] is the link to the documentation for the Subtotal function.
I understand what GroupBy and Function parameters do, but what exactly is the TotalList parameter for? Microsoft describes it as:
"An array of 1-based field offsets, indicating the fields to which the subtotals are added."
How are these offsets being read? In pairs for row and column offset? In examples I see whole arrays of many numbers being used for this. How do I make use of this? [1]: https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.range.subtotal?view=excel-pia
CodePudding user response:
You pass an array of as many numbers as you have columns for which you want subtotals calculated. If you only have one column to subtotal, you can just pass in a single number in place of an array (at least, in VBA that works)
Eg: (in VBA) -
Range("A1").CurrentRegion.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(3, 5)
would group a table of data starting in A1, according to the first column, and add subtotals in the third and fifth columns.