问题描述
Hai,
我们有像在windows7 / vista中那样预览文档的要求
预览窗格并且必须实现Winforms中的搜索功能。为此,
我已将Ms office docuemnts,Excel Sheets和Power Point文档以html格式加载到Webbrowser Control中。现在我们需要在该webbrowser中实现搜索功能控制。
为此,我们使用以下代码实现了搜索功能
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;
}
此代码适用于在 word Document 中搜索所有出现的字符串值。
但是当它来到 Excel和PPt文档时,这段代码无法正常工作。只查找字符串的第一次出现,其他出现的事件没有调试时发现。
我发现,对于word文档IHTMLDocument2对象存储了innerHTML和innerText中的html内容以及一些值。
但是对于Excel,它仅使用框架将文本存储在innerHTML中,并且工作表被引用到本地临时.html文件,并且它没有任何innerText内容显示为null。 br />
请提供搜索加载html内容的webbrowser控件中的文本的解决方案,该内容是从 Excel,PPT 转换为html类型和在webbrowser控件中显示。
如果您有任何疑问,请感受问我。
谢谢。
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.
推荐答案
这篇关于如何在WebBrowser控件中搜索文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!