C# 在set_范围之后调用set_样式

C# 在set_范围之后调用set_样式,c#,ms-word,styles,interop,C#,Ms Word,Styles,Interop,我正在尝试以编程方式更新Word文档。 我选择一个单元格,然后更新其范围的文本,最后,我想在该范围的特定部分调用set_样式。但是,执行此操作时,样式将应用于整个范围 下面是一段代码来演示我目前正在做的事情: Cell targetCell = _myWordDocument.Tables[1].Cell(i, 4); targetCell.Range.Text = "Here is the text I will update later on"; //position before ins

我正在尝试以编程方式更新Word文档。 我选择一个单元格,然后更新其范围的文本,最后,我想在该范围的特定部分调用set_样式。但是,执行此操作时,样式将应用于整个范围

下面是一段代码来演示我目前正在做的事情:

Cell targetCell = _myWordDocument.Tables[1].Cell(i, 4);
targetCell.Range.Text = "Here is the text I will update later on";

//position before inserting the text 
int startFormat = targetCell.Start +12;  
//end position
int endFormat = targetCell.End - 23;
//new range    
Range formatMe = targetCell;             
formatMe.SetRange(startFormat, endFormat);
// this works just fine
formatMe.Bold = 1;                          
//this, however does not as it applies to the whole text
//not only the sub range I defined above
object style_name = "Heading 1"; // or Tag or whatever...
formatMe.set_Style(ref style_name);              

有人能给我一些建议吗?

在单词、段落和字符样式中有两种主要的样式。您正在使用段落样式,因此它将应用于整个段落。尝试使用角色样式。请看这里: