Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
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
 
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 20-Dec-12 3:16am
Edited 20-Dec-12 18:22pm
v4
Comments
Richard MacCutchan at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Comments
V G S Naidu A at 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.
Edo Tzumer at 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)

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 Afzaal Ahmad Zeeshan 120
4 DamithSL 115
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100