以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  单个word文档 检索结果显示  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=133078)

--  作者:天一生水
--  发布时间:2019/4/6 9:03:00
--  单个word文档 检索结果显示
请问老师:如图红色框中的检索结果,怎样写代码?
谢谢!

图片点击可在新窗口打开查看此主题相关图片如下:111.jpg
图片点击可在新窗口打开查看

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:单文件检索测试.rar

按钮代码如下:

\'\'\'
e.Form.Controls("TextBox3").text = ""      \'清空
e.Form.Controls("Label2").text = ""

If e.Form.Controls("TextBox2").text = ""  OrElse e.Form.Controls("TextBox1").text  = "" Then
    msgbox("请录入需检索信息!")
    Return
Else
    
    Dim app As New MSWord.Application
    e.Form.Controls("Label2").text = "正在检索中......"
    Dim st As Date = Date.Now   \'开始计时
    try
        Dim s As String = ""
        Dim doc = app.Documents.Open(e.Form.Controls("TextBox1").text)
        Dim gjzs As String = e.Form.Controls("TextBox2").text
        Dim flag As Boolean = False
        For Each gjz As String In gjzs.split("、")
            app.ActiveWindow.Selection.WholeStory
            With app.ActiveWindow.Selection.Find
                .HitHighlight(gjz, RGB(255, 255, 0), , , , , , , True)   \'高亮显示找到的关键字
            End With
            If app.ActiveWindow.Selection.Find.Execute Then flag = True
            If flag = False  Then
                e.Form.Controls("TextBox3").text = "没有找到!"
                Doc.close
            Else
                ’s = s & IIF(s>"", "、", "") & gjz
                ’e.Form.Controls("TextBox3").text = "找到包含的关键字有" & s.Split("、").Length & "个,如下:" & "、" & s & vbcrlf & "未找到包含的关键字有" & s.Split("、").Length & "个,如下:" & "、" & s
                
                If e.Form.Controls("CheckBox1").Checked = True Then    \'是否打开word文档
                    app.Visible = True
                Else
                    app.Visible = False
                    app.quit
                End If
            End If
        Next
        
    catch ex As exception
        msgbox(ex.message)
        app.Quit
    finally
    End try
    e.Form.Controls("Label2").text = "检索完毕!"  & "耗时: " & (Date.Now - st).TotalSeconds & "秒"
End If



--  作者:有点蓝
--  发布时间:2019/4/6 12:54:00
--  
\'\'\'
e.Form.Controls("TextBox3").text = ""      \'清空
e.Form.Controls("Label2").text = ""

If e.Form.Controls("TextBox2").text = ""  OrElse e.Form.Controls("TextBox1").text  = "" Then
    msgbox("请录入需检索信息!")
    Return
Else
    
    Dim app As New MSWord.Application
    e.Form.Controls("Label2").text = "正在检索中......"
    Dim st As Date = Date.Now   \'开始计时
    try
        Dim s As String = ""
        Dim lst As new List(of String)
        Dim doc = app.Documents.Open(e.Form.Controls("TextBox1").text)
        Dim gjzs As String = e.Form.Controls("TextBox2").text
        Dim flag As Boolean = False
        Dim arr() As String = gjzs.split("、")
        For Each gjz As String In arr
            app.ActiveWindow.Selection.WholeStory
            With app.ActiveWindow.Selection.Find
                If .HitHighlight(gjz, RGB(255, 255, 0), , , , , , , True)   \'高亮显示找到的关键字
                    lst.Add(gjz)
                End If
            End With
            If app.ActiveWindow.Selection.Find.Execute Then flag = True
            If flag = False  Then
                e.Form.Controls("TextBox3").text = "没有找到!"
                Doc.close
            End If
        Next
        For Each gjz As String In arr
            If lst.Contains(gjz) = False
                s = s & gjz & "、"
            End If
        Next
        e.Form.Controls("TextBox3").text = "找到包含的关键字有" & lst.Count & "个,如下:" & String.Join("、",lst.ToArray) & vbcrlf & "未找到包含的关键字有" & s.Split("、").Length & "个,如下:" &  s
        If e.Form.Controls("CheckBox1").Checked = True Then    \'是否打开word文档
            app.Visible = True
        Else
            app.Visible = False
            app.quit
        End If
    catch ex As exception
        msgbox(ex.message)
        app.Quit
    finally
    End try
    e.Form.Controls("Label2").text = "检索完毕!"  & "耗时: " & (Date.Now - st).TotalSeconds & "秒"
End If