我的要求是将样式应用于文档中的段落,我根据正则表达式条件将某些样式应用于某段落,有些段落更难分配样式,我想得到的样式取决于前段落样式
答案 0 :(得分:2)
我根据你的问题尝试这个。
word.Document myDocx = Globals.ThisAddIn.Application.ActiveDocument;
string prevParaStyle = string.Empty;
string nextParaStyle = string.Empty;
string curParaStyle = string.Empty;
foreach (word.Paragraph eachPara in myDocx.Paragraphs)
{
if (eachPara.Previous(1) != null)
prevParaStyle = ((word.Style)eachPara.Previous(1).get_Style()).NameLocal;
if(eachPara.Next(1)!=null)
nextParaStyle = ((word.Style)eachPara.Next(1).get_Style()).NameLocal;
curParaStyle = ((word.Style)eachPara.get_Style()).NameLocal;
}