Click here to Skip to main content
15,884,038 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hai,
we have a requirement like previewing the documents as like in windows7/vista
"preview Pane" and have to implement the search functionality in Winforms.For that,
I have loaded the Ms office docuemnts, and Excel Sheets and Power Point documents into Webbrowser Control in html format.Now we need to implement the search functionality in that webbrowser Control.

For that we have implemented the search functionality using the following code

C#
public bool FindNext(string text, WebBrowser webBrowser1)
        {

            IHTMLDocument2 doc = webBrowser1.Document.DomDocument as IHTMLDocument2;
   
            IHTMLSelectionObject sel =doc.selection;// (IHTMLSelectionObject)doc.selection;
            IHTMLTxtRange rng = sel.createRange() as IHTMLTxtRange;
         
            rng.collapse(false); // collapse the current selection so we start from the end of the previous range
            if (rng.findText(text, 1000000, 0))
            {
                rng.select();
                return true;
            }
            else
                FindFirst(text, webBrowser1);
            return false;
        }

This code is working fine for searching the string values in word Document for all the occurences.
But when it Comes to Excel and PPt documents this code doesn't work properly.it finds only the first occurrence of the string, other occurrences doesn't find.
while debugging i found that,for word Documents "IHTMLDocument2" object stores the html Content in "innerHTML" and "innerText" with some values.
But for Excel it stores the text in "innerHTML" only by using the Frames, and sheets are referenced to local temporary .html files and it didn't have any "innerText" content it showing as null.

Please provide the solution to search the text in webbrowser control which loaded the html content, that is converted from Excel,PPT to html type and displaying in webbrowser control.

If you have any queries please feel to ask me.

Thank You.
Posted
Updated 20-Dec-12 17:22pm
v4
Comments
Richard MacCutchan 20-Dec-12 8:43am    
Please do not mark questions as urgent; it is only urgent to you. You do not pay for this service, so any answers will be given when other members have free time to consider your issue.

1 solution

Hi Naidu,

What's the problem?

What if you add an IF statement and check if the innerText is nothing, search on the innerHTML, wouldn't that solve your issue?

Cheers,
Edo
 
Share this answer
 
v2
Comments
V G S Naidu A 27-Jan-13 23:25pm    
Thank you for reply. Actually in Excel, the innerHTML field containing the frame links like <link href="..." .../> only for the corresponding sheets.it doesn't showing the any content to search. that's why i can't able to find the text even using the innerhtml.Here in "href" path in link tag is encrypted way so we could not find the text temparary path also.i think u understand.
Joezer BH 28-Jan-13 0:57am    
Can you show us what the text looks like, with&without the encryption?

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