Foxtable(狐表)用户栏目专家坐堂 → 单个word文档 检索结果显示


  共有2004人关注过本帖树形打印复制链接

主题:单个word文档 检索结果显示

帅哥哟,离线,有人找我吗?
天一生水
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1139 积分:11245 威望:0 精华:0 注册:2017/9/26 16:30:00
单个word文档 检索结果显示  发帖心情 Post By:2019/4/6 9:03:00 [只看该作者]

请问老师:如图红色框中的检索结果,怎样写代码?
谢谢!

图片点击可在新窗口打开查看此主题相关图片如下: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



 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107440 积分:546479 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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

 回到顶部