Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a HTML I'm inserting into a Word document, that contains, among other things, ##[some_number]## tags. After the conversion I need to find them and replace them with footnotes.

My question: is there an efficient way to do it? The only thing I can think of is the following:

//I only have one paragraph
Range _range = pDoc.Paragraphs[1].Range;
for (int i = 1; i <= _range.Words.Count; i++)
{
    if (pDoc.Paragraphs[1].Range.Words[i].Text.EndsWith("##"))

//some parsing to remove the '##' and get the number


    pDoc.Footnotes.Add(_range.Words[i].Characters[1], ref missing, ref text);
}


Now this is not very efficient, especially if the document is long.
I was trying to use the Range.Find method, but I don't know how to get the proper Range object from it.

I'd appretiate any on the subject.
Posted
Updated 11-Dec-09 3:33am
v2

1 solution

Hi Team ;)
[Word 2007]Searching for keywords and adding footnotes

Code snape. Hope It will Help to You
Use using Microsoft.Office.Interop.Word;
1.
Open The Word Document
2.
Search The SearchString Through the word document
3.
If Found Add it to the footnote
4.
Kile the Word Processor.
Code
Word.ApplicationClass wordApp = new Word.ApplicationClass();
// Input box is used to get the path of the file which has to be uploaded into textbox.
string strPath = Request.PhysicalApplicationPath + @"document\GTCS.doc";
//ShowWordMht1.FilePath = "CAREER.doc";
object file = strPath;
object nullobj = System.Reflection.Missing.Value;
// here on Document.Open there should be 9 arg.
Word.Document doc = wordApp.Documents.Open(ref file,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
string m_Content = wordApp.ActiveDocument.Content.Text;

foreach (Microsoft.Office.Interop.Word.Range range in doc.Words)
{
if (range.Text.Trim() == txtSearchWord.Text.Trim())
{
//Logic Add it to the footnote

}

else
{
lblDocContent.Text = "The Search Text:- "+ txtSearchWord.Text + " Not Found. !";
}
wordwin.Attributes["src"] = "document/GTCS.doc";

}
wordApp.ActiveDocument.Close(ref nullobj, ref nullobj, ref nullobj);
Killwordproc();



Thank's
Prasanta Kumar Pradhan
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900