2014-05-15 4 views
0

C#에서 단어 문서를 읽고 있는데, 그것을 읽은 후 선택한 단락에 대한 설명을 입력해야합니다.2010 년 단어의 단락 색인을 찾는 방법

그래서 C#을 통해 단락의 색인을 찾아야합니다.

foreach (Microsoft.Office.Interop.Word.Paragraph aPar in oDoc.Paragraphs) // looping through all the paragh in document 
{ 
    Microsoft.Office.Interop.Word.Range parRng = aPar.Range; 
    string sText = parRng.Text; 
    if (sText == para[1].ToString()) // found the paragraph and i need the index of this paragraph 
    { 
     oDoc.Comments.Add(oDoc.Paragraphs[0].Range, ref comments); // to add the comment in document 
    } 
} 

해당 단락의 색인을 찾으면 해당 단락에 주석을 삽입 할 수 있습니까? 가능한가?

또는 다른 방법이 있습니까?

답변

0
   int i = 1; 
       foreach (Word.Paragraph aPar in oDoc.Paragraphs) 
       { 
       string sText = aPar.Range.Text; 
      if (sText != "\r") 
      { 
       if (sText == para[1].ToString() + "\r") 
       { 
       Word.Range range = oDoc.Paragraphs[i + 1].Range; 
       if (!range.Text.Contains("GUID:")) 
        { 
         int pEnd = aPar.Range.End; 
         string guid = "GUID:" + para[0].Replace("{", "").Replace("}", ""); 
         int length = guid.Length; 
         aPar.Range.InsertAfter(guid); 
         Word.Range parRng = oDoc.Range(pEnd, pEnd + length); 
         parRng.Font.Hidden = 1; 
         parRng.InsertParagraphAfter(); 
         } 
        } 
        } 
        i++; 
       } 
0

그것은 나를 위해 작동이

foreach (Microsoft.Office.Interop.Word.Paragraph aPar in oDoc.Paragraphs) // loads all words in document 
    { 
     Microsoft.Office.Interop.Word.Range parRng = aPar.Range; 
     string sText = parRng.Text.Replace("\r",""); 
     if (sText == txtBoxParagraph.Text) // found the paragraph and i need the index of this paragraph 
     { 
      oDoc.Comments.Add(parRng, txtBoxComments.Text); // to add the comment in document 
     } 
    } 

보십시오.

관련 문제