0

Currently I retrieve footnote text in a paragraph using

     foreach (Microsoft.Office.Interop.Word.Paragraph para in doc.Paragraphs)
        {
            Microsoft.Office.Interop.Word.Range range = para.Range.Duplicate;

            string x = "";
            for (int i = 1; i <= para.Range.Footnotes.Count; i++)
            {
                x = para.Range.Footnotes[i].Range.Text;
             }
        }

But the text "x" I want to append next to footnote script in the paragraph for processing. I would like to know if there is anyway to navigate using location or split the paragraph using any delimiter for footnote marker so that I can recreate the text with body and footnote text appended to it.

Kazimierz Jawor
  • 18,861
  • 7
  • 35
  • 55
Arun
  • 1
  • 1

1 Answers1

0

Best option, in my opinion, is to use .Find property of Range object. You will need to search for ^f which represent footnote mark (within range).

First, I show you the code in VBA (which language I know much better):

para.Range.Select
Selection.Find.Execute "^f"
//'the code below will insert footnote text after your footnote mark
Selection.InsertAfter " " & Selection.Footnotes(1).Range.Text

I think in C# it will look as follows (or similar, not tested):

para.Range.Select;
Selection.Find.Execute("^f", ref Type.Missing, ref Type.Missing, ref Type.Missing, ref Type.Missing,
                             ref Type.Missing, ref Type.Missing, ref Type.Missing, ref Type.Missing,
                             ref Type.Missing, ref Type.Missing, ref Type.Missing, ref Type.Missing,
                             ref Type.Missing, ref Type.Missing);

Selection.InsertAfter(string.Format(" {0}", Selection.Footnotes[1].Range.Text));
Kazimierz Jawor
  • 18,861
  • 7
  • 35
  • 55