从 C# 在 Word 中生成多级列表

Generate multilevel list in Word from C#

我有 Microsoft Word docx 文档,其中有一些文本和占位符。此文件是用 C# 应用程序中的数据填充的模板。我对一件事有疑问 - 多级列表。

在 docx 中我有这个:

在 C# 中,我使用的是这段代码:

Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
...
object ph = "{placeholder}";
string replaceWith = "item1" + "\n" + "item2";
wordApp.Selection.Find.Execute(ref ph);
wordApp.Selection.Text = replaceWith;

它生成预期的结果:

但我想用这样的东西:

...
string replaceWith = "item1" + "\n\t" + "item2";
...
wordApp.Selection.Text = replaceWith;

要生成它(最好使用 MS Word 中的项目符号样式(第二级是空项目符号)):

但是输出(错误)是:

不可能在字符串中包含这种段落格式。是的,当按下 TAB 键时,可以将 Word 应用程序设置为按照您为最终用户描述的那样运行。但这不会延续到编程 API。插入字符串后,代码需要在第二段应用大纲级别。类似于:

Selection.Paragraphs[2].OutlineDemote

另一种选择是

  • {占位符1}
    • {placeholder2}