DocumentBase.Lists 屬性
取得 Lists 集合,包含文件中所有已格式化的清單。
命名空間: Microsoft.Office.Tools.Word
組件: Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)
語法
'宣告
Public ReadOnly Property Lists As Lists
public Lists Lists { get; }
屬性值
型別:Microsoft.Office.Interop.Word.Lists
Lists 集合,包含文件中所有已格式化的清單。
範例
下列程式碼範例會將文字加入至前兩個段落中、套用清單範本至段落,然後顯示訊息說明文件中的清單數目。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。
Private Sub DocumentLists()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Me.Paragraphs(1).Range.InsertParagraphAfter()
Me.Paragraphs(1).Range.Text = "This is the first paragraph."
Me.Paragraphs(2).Range.Text = "This is the second paragraph."
Dim Start As Object = Me.Paragraphs(1).Range.Start
Dim [End] As Object = Me.Paragraphs(2).Range.End
Dim myRange As Word.Range = Me.Range(Start, [End])
Dim index As Object = 1
Dim myTemplate As Word.ListTemplate = Application.ListGalleries( _
Microsoft.Office.Interop.Word.WdListGalleryType.wdNumberGallery). _
ListTemplates.Item(index)
myRange.ListFormat.ApplyListTemplate(myTemplate)
MessageBox.Show("Total lists in document: " & Me.Lists.Count.ToString())
End Sub
private void DocumentLists()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
this.Paragraphs[1].Range.InsertParagraphAfter();
this.Paragraphs[1].Range.Text = "This is the first paragraph.";
this.Paragraphs[2].Range.Text = "This is the second paragraph.";
object Start = this.Paragraphs[1].Range.Start;
object End = this.Paragraphs[2].Range.End;
Word.Range myRange = this.Range(ref Start,
ref End);
object index = 1;
Word.ListTemplate myTemplate = Application.ListGalleries[Microsoft.Office.Interop.Word.WdListGalleryType.wdNumberGallery].ListTemplates.get_Item(ref index);
myRange.ListFormat.ApplyListTemplate(myTemplate,
ref missing, ref missing, ref missing);
MessageBox.Show ("Total lists in document: " +
this.Lists.Count.ToString());
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。