Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,

i have displayed the Excel Content in webbrowser Control using the convert function as like below.
C#
Aplicationclass ac = new ApplicationClass();

               // Now we open the document.
               Workbook doc = ac.Workbooks.Open(fileName, m,  readOnly,
                    m,  m,  m,  m,  m,  m,  m,
                    m,  m,  m,  m,  m);
               // Create a temp file to save the HTML file to.
               string tempFileName = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + g.ToString() + ".html";
               // Cast these items to object.  The methods we're calling
               // only take object types in their method parameters.
               object newFileName = (object)tempFileName;
               // We will be saving this file as HTML format.
               object fileType = (object)Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
               // Save the file.
               doc.SaveAs( newFileName,  fileType,
                    m,  m,  m,  m,XlSaveAsAccessMode.xlExclusive , m,  m,  m,
                    m,  m);


it's loading correctly. but i need to implement the search functionality in webbrowser Control to find the text for that i have used the following method as like below

C#
public bool FindNext(string text, WebBrowser webBrowser1)
       {
           IHTMLDocument2 doc = webBrowser1.Document.DomDocument as IHTMLDocument2;

           IHTMLSelectionObject sel =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, 100000, 0))
           {   rng.select();
               return true;
           }
           else
               FindFirst(text, webBrowser1);
           return false;
       }



it find's the first matched letter in the Excel document but it didn't iterate and not navigating to another matched text.
I worked with the same logic in word Document loading in Webbrowser Control. it's working fine.
But it didn't worked in Excel document why ?

IHTMLSelectionObject sel =doc.selection;


here sel object giving the type as "None" for excel documents but for word documents it's giving the type as "text".

What to do to implement the search functionality for excel docuemnts in Webbrowser Control.


Thank you
Posted
Updated 17-Dec-12 22:41pm
v2

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