下面是C#操作Word在书签中加入用数字列表的段落中再加入项目符号的段落的示例代码:

using Word = Microsoft.Office.Interop.Word;

// 打开Word文档
Word.Application wordApp = new Word.Application();
Word.Document doc = wordApp.Documents.Open(@"C:\example.docx");

// 获取书签对象
Word.Bookmark bookmark = doc.Bookmarks["MyBookmark"];

// 获取书签位置的段落对象
Word.Range range = bookmark.Range.Paragraphs[1].Range;

// 添加用数字列表的段落
Word.List list = doc.Lists.Add(range, Word.WdListType.wdListOutlineNumbered);
Word.ListLevel level = list.ListLevels[1];
level.NumberFormat = "%1.";
level.TrailingCharacter = Word.WdTrailingCharacter.wdTrailingTab;
level.NumberStyle = Word.WdListNumberStyle.wdListNumberStyleArabic;

// 在数字列表的段落后面添加用项目符号的段落
Word.Paragraph para = doc.Content.Paragraphs.Add();
para.Range.InsertAfter("This is a paragraph with a bullet point.");
para.Range.ListFormat.ApplyBulletDefault(Word.WdDefaultListBehavior.wdWord10ListBehavior);
para.Range.InsertParagraphAfter();

// 关闭Word文档
doc.Close();
wordApp.Quit();

注意:上述代码需要引用Microsoft.Office.Interop.Word命名空间


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

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