C# 使用 Interop.Word 继续编号项目列表
使用 C# 和 Interop.Word 库继续编号项目列表
本文将介绍 5 种使用 C# 和 Interop.Word 库继续编号项目列表的方法,适用于需要在 Word 文档中继续已存在的项目编号的情况。
代码示例:
1.
using Microsoft.Office.Interop.Word;
// 创建 Word 应用程序对象
Application wordApp = new Application();
// 打开 Word 文档
Document doc = wordApp.Documents.Open(@"C:\Test.docx");
// 获取项目列表
ListGalleries galleries = doc.ListGalleries;
// 继续编号
galleries[Word.WdListGalleryType.wdNumberGallery].ListTemplates[1].ContinuePreviousListNumbering();
2.
using Microsoft.Office.Interop.Word;
// 创建 Word 应用程序对象
Application wordApp = new Application();
// 打开 Word 文档
Document doc = wordApp.Documents.Open(@"C:\Test.docx");
// 获取项目列表
ListGalleries galleries = doc.ListGalleries;
// 继续编号
galleries[Word.WdListGalleryType.wdNumberGallery].ListTemplates[2].ContinuePreviousListNumbering();
3.
using Microsoft.Office.Interop.Word;
// 创建 Word 应用程序对象
Application wordApp = new Application();
// 打开 Word 文档
Document doc = wordApp.Documents.Open(@"C:\Test.docx");
// 获取项目列表
ListGalleries galleries = doc.ListGalleries;
// 继续编号
galleries[Word.WdListGalleryType.wdNumberGallery].ListTemplates[3].ContinuePreviousListNumbering();
4.
using Microsoft.Office.Interop.Word;
// 创建 Word 应用程序对象
Application wordApp = new Application();
// 打开 Word 文档
Document doc = wordApp.Documents.Open(@"C:\Test.docx");
// 获取项目列表
ListGalleries galleries = doc.ListGalleries;
// 继续编号
galleries[Word.WdListGalleryType.wdNumberGallery].ListTemplates[4].ContinuePreviousListNumbering();
5.
using Microsoft.Office.Interop.Word;
// 创建 Word 应用程序对象
Application wordApp = new Application();
// 打开 Word 文档
Document doc = wordApp.Documents.Open(@"C:\Test.docx");
// 获取项目列表
ListGalleries galleries = doc.ListGalleries;
// 继续编号
galleries[Word.WdListGalleryType.wdNumberGallery].ListTemplates[5].ContinuePreviousListNumbering();
注意:
- 以上代码示例中,
"C:\Test.docx"应该替换为实际的 Word 文档路径。 ListTemplates[x]中的x表示要使用的项目列表模板的索引,从 1 开始。
希望本文能够帮助您在 C# 代码中使用 Interop.Word 库继续编号项目列表。
原文地址: https://www.cveoy.top/t/topic/o0fH 著作权归作者所有。请勿转载和采集!