NamedRange.Subtotal 方法

定义

NamedRange 控件创建小计。

public object Subtotal (int GroupBy, Microsoft.Office.Interop.Excel.XlConsolidationFunction Function, object TotalList, object Replace, object PageBreaks, Microsoft.Office.Interop.Excel.XlSummaryRow SummaryBelowData = Microsoft.Office.Interop.Excel.XlSummaryRow.xlSummaryBelow);
abstract member Subtotal : int * Microsoft.Office.Interop.Excel.XlConsolidationFunction * obj * obj * obj * Microsoft.Office.Interop.Excel.XlSummaryRow -> obj
Public Function Subtotal (GroupBy As Integer, Function As XlConsolidationFunction, TotalList As Object, Optional Replace As Object, Optional PageBreaks As Object, Optional SummaryBelowData As XlSummaryRow = Microsoft.Office.Interop.Excel.XlSummaryRow.xlSummaryBelow) As Object

参数

GroupBy
Int32

要作为分组依据的字段,是从 1 开始的整数偏移量。

TotalList
Object

一个从 1 开始的字段偏移量数组,指示要将小计添加到的字段。

Replace
Object

如果替换现有的小计,则为 true。 默认值为 false

PageBreaks
Object

如果在每组后面添加分页符,则为 true。 默认值为 false

SummaryBelowData
XlSummaryRow

Places与分类汇总相关的摘要数据。可以是以下XlSummaryRow值之一: xlSummaryAbovexlSummaryBelow (默认)

返回

示例

下面的代码示例为 NamedRange创建分类汇总。 分类汇总是 中 NamedRange所有三个字段的总和。

此示例适用于文档级自定义项。

private void CreateSubtotal()
{
    this.Range["A1"].Value2 = "Row 1";
    this.Range["B1"].Value2 = "Row 2";
    this.Range["C1"].Value2 = "Row 3";

    this.Range["A2", "A5"].Value2 = 10;
    this.Range["B2", "B5"].Value2 = 20;
    this.Range["C2", "C5"].Value2 = 30;

    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "C5"],
        "namedRange1");

    int[] fields = new int[] { 1, 2, 3 };
    namedRange1.Subtotal(1, Excel.XlConsolidationFunction.xlSum,
        fields, Excel.XlSummaryRow.xlSummaryBelow);
}
Private Sub CreateSubtotal()
    Me.Range("A1").Value2 = "Row 1"
    Me.Range("B1").Value2 = "Row 2"
    Me.Range("C1").Value2 = "Row 3"

    Me.Range("A2", "A5").Value2 = 10
    Me.Range("B2", "B5").Value2 = 20
    Me.Range("C2", "C5").Value2 = 30

    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1", "C5"), _
        "namedRange1")

    Dim fields() As Integer = {1, 2, 3}
    namedRange1.Subtotal(1, Excel.XlConsolidationFunction.xlSum, _
        fields, , , Excel.XlSummaryRow.xlSummaryBelow)
End Sub

注解

可选参数

有关可选参数的信息,请参阅 Office 解决方案中的可选参数

适用于