DocumentBase.ListTemplates 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个 ListTemplates 集合,该集合表示文档的所有列表格式。
public Microsoft.Office.Interop.Word.ListTemplates ListTemplates { get; }
属性值
一个 ListTemplates 集合,表示文档的所有列表格式。
示例
下面的代码示例向前两个段落中添加文本,将列表模板应用于段落,然后显示一条消息,其中显示文档中的列表数。 若要使用此示例,请在 ThisDocument 文档级项目的类中运行它。
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());
}
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