下面是使用 C# 编写的 Word 项目列表 ListGalleries 继续编号代码:

using Microsoft.Office.Interop.Word;

// 获取文档对象
Application wordApp = new Application();
Document wordDoc = wordApp.Documents.Open('D:\test.docx');

// 获取项目列表对象
ListGalleries listGalleries = wordDoc.ListGalleries;

// 获取指定类型的项目列表
ListGallery listGallery = listGalleries[WdListGalleryType.wdNumberGallery];

// 获取项目列表模板
ListTemplate listTemplate = listGallery.ListTemplates[1];

// 获取项目列表对象
List list = wordDoc.Lists.Add(listTemplate);

// 设置继续编号
list.ListParagraphs[list.ListParagraphs.Count].Range.ListFormat.ListLevelNumber = 1;

// 保存并关闭文档
wordDoc.Save();
wordDoc.Close();

// 退出 Word 应用程序
wordApp.Quit();

以上代码中,我们首先创建了一个 Word 应用程序对象以及一个文档对象,然后获取了项目列表对象和指定类型的项目列表对象。接着,我们获取了项目列表模板并使用该模板创建了一个新的项目列表对象。最后,通过设置最后一项的 ListLevelNumber 属性,实现了继续编号的功能。最后,我们保存并关闭了文档,并退出了 Word 应用程序。

C# Word 项目列表 ListGalleries 继续编号代码示例

原文地址: https://www.cveoy.top/t/topic/o0eQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录