다음을 통해 공유


NamedRange.Table(Object, Object) Method

Definition

Creates a data table based on input values and formulas that you define in a worksheet.

public object Table (object RowInput, object ColumnInput);
abstract member Table : obj * obj -> obj
Public Function Table (Optional RowInput As Object, Optional ColumnInput As Object) As Object

Parameters

RowInput
Object

A single cell to use as the row input for your table.

ColumnInput
Object

A single cell to use as the column input for your table.

Returns

Examples

The following code example uses the Table method to create a formatted multiplication table in a NamedRange.

This example is for a document-level customization.

private void CreateTable()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "K11"],
        "namedRange1");

    this.Range["A1"].Formula = "=A12*A13";
    for (int i = 2; i <= 11; i++)
    {
        ((Excel.Range)this.Cells[i, 1]).Value2 = i - 1;
        ((Excel.Range)this.Cells[1, i]).Value2 = i - 1;
    }

    namedRange1.Table(this.Range["A12"],
        this.Range["A13"]);
    Excel.Range region = this.Range["A1"].CurrentRegion;
    ((Excel.Range)region.Rows[1]).Font.Bold = true;
    ((Excel.Range)region.Columns[1]).Font.Bold = true;
    ((Excel.Range)region.Columns).AutoFit();
}
Private Sub CreateTable()
    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1", "K11"), _
        "namedRange1")

    Me.Range("A1").Formula = "=A12*A13"
    Dim i As Integer
    For i = 2 To 11
        CType(Me.Cells(i, 1), Excel.Range).Value2 = i - 1
        CType(Me.Cells(1, i), Excel.Range).Value2 = i - 1
    Next i

    namedRange1.Table(Me.Range("A12"), Me.Range("A13"))
    Dim [region] As Excel.Range = Me.Range("A1").CurrentRegion
    CType([region].Rows(1), Excel.Range).Font.Bold = True
    CType([region].Columns(1), Excel.Range).Font.Bold = True
    CType([region].Columns, Excel.Range).AutoFit()
End Sub

Remarks

Use data tables to perform a what-if analysis by changing certain constant values on your worksheet to see how values in other cells are affected.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Applies to