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++;
}
How to find the index of a paragraph in word 2010
-
23-07-2023 - |
سؤال
I am reading a word document in c#,where after reading it, I need to enter a comment for selected paragraphs.
So I need to find the index of paragraph through c#, is it possible??
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
}
}
If I found the index of that paragraph, Can I insert the comment on that paragraph? Is it possible?
Or is there any other way to do this?
المحلول 2
نصائح أخرى
Try this
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
}
}
It works for me.
لا تنتمي إلى StackOverflow