2

我正在尝试以编程方式更新 Word 文档。我选择一个单元格,然后更新其范围的文本,最后,我想在该范围的特定部分调用 set_style。但是,这样做时,样式适用于整个范围。

这是一段代码来演示我目前在做什么:

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);              

有人有我可以使用的提示吗?

4

0 回答 0