简体   繁体   English

如何在C#Word Interop中指定范围之前确定行范围

[英]How to identify the range of lines before the specified range in c# word interop

I have identified a range in a word document through identifying the range of a certain word using the following code: 我已通过使用以下代码确定某个单词的范围来确定单词文档中的范围:

object start = 0, end = 0;
Word.Range myRange = doc.Range(ref start, end);
if(myRange.Find.Execute("wordtofind"))
{
    //some codes here
}

I am wondering if there is a way I can find to get the range of a specific line in the document that is 3 lines/paragraphs before that "wordtofind"? 我想知道是否有一种方法可以找到文档中某个特定行的范围,该范围是该“ wordfind”之前的3行/段落?

Note: 注意:

The "wordtofind" is the only word in that particular line where it can be found. “找到单词”是该行中唯一可以找到的单词。

You can use the Range.MoveEnd method to move the Range "backwards" by a certain number of specified units (see the Word.WdUnits enumeration). 您可以使用Range.MoveEnd方法将“范围”向后移动一定数量的指定单位(请参阅Word.WdUnits枚举)。

To move back 3 paragraphs: 移回三段:

object unitPara as Word.WdUnits.wdParagraph;
object moveBack3 = -3;
myRange.MoveEnd(ref unitPara, ref moveBack3);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM