Excel API Library for .NET - Sample Browser | Document Solutions | Add subtotal
[
フレーム]
Add subtotal to a range with IRange.Subtotal
//create a new workbook
var workbook = new GrapeCity.Documents.Excel.Workbook();
IRange targetRange = workbook.ActiveSheet.Range["A1:C9"];
// Set data
targetRange.Value = new object[,]
{
{"Player", "Side", "Commander"},
{1, "Soviet", "AI"},
{2, "Soviet", "AI"},
{3, "Soviet", "Human"},
{4, "Allied", "Human"},
{5, "Allied", "Human"},
{6, "Allied", "AI"},
{7, "Empire", "AI"},
{8, "Empire", "AI"}
};
// Subtotal
targetRange.Subtotal(groupBy: 2, // Side
subtotalFunction: ConsolidationFunction.Count,
totalList: new[] { 2 } // Side
);
targetRange.AutoFit();
// Save to an excel file
workbook.Save("AddSubtotal.xlsx");
' Create a new Workbook
Dim workbook As New Workbook
Dim targetRange As IRange = workbook.ActiveSheet.Range("A1:C9")
' Set data
targetRange.Value = New Object(,) {
{"Player", "Side", "Commander"},
{1, "Soviet", "AI"},
{2, "Soviet", "AI"},
{3, "Soviet", "Human"},
{4, "Allied", "Human"},
{5, "Allied", "Human"},
{6, "Allied", "AI"},
{7, "Empire", "AI"},
{8, "Empire", "AI"}
}
' Subtotal
targetRange.Subtotal(groupBy:=2, ' Side
subtotalFunction:=ConsolidationFunction.Count,
totalList:={2} ' Side
)
targetRange.AutoFit()
' save to an excel file
workbook.Save("AddSubtotal.xlsx")