共用方式為


ListObject.DataBodyRange Property

Definition

Gets a Range that represents the range that contains the data area in the list between the header row and the insert row.

public:
 property Microsoft::Office::Interop::Excel::Range ^ DataBodyRange { Microsoft::Office::Interop::Excel::Range ^ get(); };
public Microsoft.Office.Interop.Excel.Range DataBodyRange { get; }
member this.DataBodyRange : Microsoft.Office.Interop.Excel.Range
Public ReadOnly Property DataBodyRange As Range

Property Value

A Range that represents the range that contains the data area in the list between the header row and the insert row.

Examples

The following code example creates a ListObject and then shows the number of rows that are available for data.

This example is for a document-level customization.

private void ListObject_DataBodyRange()
{
    Microsoft.Office.Tools.Excel.ListObject list1 = 
        this.Controls.AddListObject(
        this.Range["A1", "C4"], "list1");
    Excel.Range list1BodyRange = list1.DataBodyRange;
    int numberOfRows = list1BodyRange.Rows.Count;
    MessageBox.Show("The DataBodyRange of list1 has " +
        numberOfRows.ToString() + " rows.");
}
Private Sub ListObject_DataBodyRange()
    Dim List1 As Microsoft.Office.Tools.Excel.ListObject = _
        Me.Controls.AddListObject(Me.Range("A1", "C4"), "List1")
    Dim List1BodyRange As Excel.Range = List1.DataBodyRange
    Dim numberOfRows As Integer = List1BodyRange.Rows.Count
    MessageBox.Show("The DataBodyRange of list1 has " & _
        numberOfRows.ToString() & " rows.")

End Sub

Remarks

If the ListObject control does not have a DataBodyRange, this property returns null.

Applies to