NamedRange.ListObject 屬性
取得 NamedRange 控制項的 Microsoft.Office.Interop.Excel.ListObject。
命名空間: Microsoft.Office.Tools.Excel
組件: Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)
語法
'宣告
ReadOnly Property ListObject As ListObject
Get
ListObject ListObject { get; }
屬性值
型別:Microsoft.Office.Interop.Excel.ListObject
NamedRange 控制項的 Microsoft.Office.Interop.Excel.ListObject。
範例
下列程式碼範例會在 NamedRange 內建立 ListObject,然後使用 NamedRange 的 ListObject 屬性顯示 ListObject 中的列數。
這是示範文件層級自訂的範例。
Private Sub GetListObject()
Me.Range("B2").Value2 = "Row 1"
Me.Range("C2").Value2 = "Row 2"
Me.Range("D2").Value2 = "Row 3"
Me.Range("B3", "B5").Value2 = 10
Me.Range("C3", "C5").Value2 = 20
Me.Range("D3", "C5").Value2 = 30
Dim listObject1 As Microsoft.Office.Tools.Excel.ListObject _
= Me.Controls.AddListObject(Me.Range("B2", "D5"), _
"listObject1")
Dim getListObjectRange As _
Microsoft.Office.Tools.Excel.NamedRange = _
Me.Controls.AddNamedRange(Me.Range("A1", "E6"), _
"getListObjectRange")
getListObjectRange.Select()
Dim numberOfRows As Integer = _
getListObjectRange.ListObject.DataBodyRange.Rows.Count
MessageBox.Show("The DataBodyRange of the ListObject contains " & _
numberOfRows & " rows.")
End Sub
private void GetListObject()
{
this.Range["B2", missing].Value2 = "Row 1";
this.Range["C2", missing].Value2 = "Row 2";
this.Range["D2", missing].Value2 = "Row 3";
this.Range["B3", "B5"].Value2 = 10;
this.Range["C3", "C5"].Value2 = 20;
this.Range["D3", "C5"].Value2 = 30;
Microsoft.Office.Tools.Excel.ListObject listObject1 =
this.Controls.AddListObject(
this.Range["B2", "D5"], "listObject1");
Microsoft.Office.Tools.Excel.NamedRange getListObjectRange =
this.Controls.AddNamedRange(
this.Range["A1", "E6"], "getListObjectRange");
getListObjectRange.Select();
int numberOfRows =
getListObjectRange.ListObject.DataBodyRange.Rows.Count;
MessageBox.Show("The DataBodyRange of the ListObject contains " +
numberOfRows + " rows.");
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。