以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何找出文档包括的字符串  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=70797)

--  作者:huhu
--  发布时间:2015/6/29 13:59:00
--  [求助]如何找出文档包括的字符串

如何在一个目录,目录包括好多doc和pdf文档,我如何能做到自动检索这些文档中是否包括某些字符串

不是找出某列包括的字符串,是找出文档是否报告指定的字符串。

这个有办法可以实现吗?


--  作者:大红袍
--  发布时间:2015/6/29 14:18:00
--  

循环文件夹的所有文件,比较文件名即可。

 

http://www.foxtable.com/help/topics/0341.htm

 


--  作者:huhu
--  发布时间:2015/6/29 14:22:00
--  
以下是引用大红袍在2015/6/29 14:18:00的发言:

循环文件夹的所有文件,比较文件名即可。

 

http://www.foxtable.com/help/topics/0341.htm

 

不是找文件名。

比如有3个doc文档,我需要查找这3个文档内容里面是否包括字符串ABC,不是3个文件名是否包括ABC。是内容。


--  作者:大红袍
--  发布时间:2015/6/29 14:23:00
--  

1、如果是word,可以用vba去控制;

 

2、如果是pdf,必须用额外的dll文件去查询内容。


--  作者:大红袍
--  发布时间:2015/6/29 14:35:00
--  

 你这个设计到文档检索的功能,现在要弄做一个这样的软件出来,也能卖很高的价格,主要是性能方面要优化。

 

 基本,就是打开word、pdf,取出内容检索,具体可看4楼;少量的文件,还是可以查的;大量文件的话,还得考虑怎么每次打开的时候,把内容更新到数据,以后直接去查数据库。

 

http://www.cnblogs.com/Teco/archive/2012/04/20/2460595.html

 

https://msdn.microsoft.com/zh-cn/library/f1f367bx(v=vs.80).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-3

 

 


--  作者:huhu
--  发布时间:2015/6/29 16:13:00
--  
以下是引用大红袍在2015/6/29 14:35:00的发言:

 你这个设计到文档检索的功能,现在要弄做一个这样的软件出来,也能卖很高的价格,主要是性能方面要优化。

 

 基本,就是打开word、pdf,取出内容检索,具体可看4楼;少量的文件,还是可以查的;大量文件的话,还得考虑怎么每次打开的时候,把内容更新到数据,以后直接去查数据库。

 

http://www.cnblogs.com/Teco/archive/2012/04/20/2460595.html

 

https://msdn.microsoft.com/zh-cn/library/f1f367bx(v=vs.80).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-3

 

 这个这个对我来说太难了,我就想从最简单的做起,比较就一个文档,而且就是word。

我需要做到在文本框输入要查找的字符串,比如A,B,C,123等,点击搜索,然后就自动查找。


--  作者:大红袍
--  发布时间:2015/6/29 16:47:00
--  
Dim app As New MSWord.Application
try
    For Each file As String In FileSys.GetFiles("d:\\")
        If file.ToLower.EndsWith(".doc") Then
           
            Dim doc = app.Documents.Open(file)
           
            If app.ActiveWindow.Selection.Find.Execute("test") = False Then
                Doc.close
            Else
                output.Show(file)
            End If
           
        End If
    Next
    app.Visible = True
catch ex As exception
    msgbox(ex.message)
    app.Quit
finally
   
End try

--  作者:huhu
--  发布时间:2015/6/30 15:50:00
--  

请帮我看看,红色的代码怎么改,才能在msgbox(s)弹出包含关键字的文档目录。

 

Dim app As New MSWord.Application
try
    Dim dlg As New FolderBrowserDialog
    If dlg.ShowDialog = DialogResult.Ok Then
        MessageBox.Show("需要检索的文档目录是:" & dlg.SelectedPath,"提示")
    End If
    For Each file As String In FileSys.GetFiles(dlg.SelectedPath)
        If file.ToLower.EndsWith(".doc") Then
            Dim doc = app.Documents.Open(file)
            Dim gjz As String = Tables("说明书检索").Current("说明书关键字")
            If app.ActiveWindow.Selection.Find.Execute(gjz) = False  Then
                Doc.close
            Else
                Dim s As String = file
                For Each f1 As String In files
                    s = s & vbcrlf & f1
                Next
            End If
        End If
    Next
    mesbox(s)
    app.Visible = True
catch ex As exception
    msgbox(ex.message)
    app.Quit
finally
End try


--  作者:大红袍
--  发布时间:2015/6/30 15:56:00
--  
Dim app As New MSWord.Application
try
    Dim dlg As New FolderBrowserDialog
    If dlg.ShowDialog = DialogResult.Ok Then
        MessageBox.Show("需要检索的文档目录是:" & dlg.SelectedPath,"提示")
    End If
    Dim s As String = ""
    For Each file As String In FileSys.GetFiles(dlg.SelectedPath)
        If file.ToLower.EndsWith(".doc") Then
            Dim doc = app.Documents.Open(file)
            Dim gjz As String = Tables("说明书检索").Current("说明书关键字")
            If app.ActiveWindow.Selection.Find.Execute(gjz) = False  Then
                Doc.close
            Else
                s = s & IIF(s>"", vbcrlf, "") & file
            End If
        End If
    Next
    msgbox(s)
    app.Visible = True
catch ex As exception
    msgbox(ex.message)
    app.Quit
finally
End try

--  作者:huhu
--  发布时间:2015/6/30 16:37:00
--  

Dim app As New MSWord.Application
try
    Dim dlg As New FolderBrowserDialog
    If dlg.ShowDialog = DialogResult.Ok Then
        MessageBox.Show("需要检索的文档目录是:" & dlg.SelectedPath,"提示")
    End If
    Dim s As String = ""
    For Each file As String In FileSys.GetFiles(dlg.SelectedPath)
        If file.ToLower.EndsWith(".doc") Then
            Dim doc = app.Documents.Open(file)
            Dim gjz As String = Tables("说明书检索").Current("说明书关键字")
            If app.ActiveWindow.Selection.Find.Execute(gjz) = False  Then
                Doc.close
               
            Else
                s = s & IIF(s>"", vbcrlf, "") & file
            End If
        End If
    Next
    If s > "" Then
        MessageBox.Show("共计找到包含关键字的文档有count个,目录如下:" & vbcrlf & s,"关键字文档查找",MessageBoxButtons.OK,MessageBoxIcon.None)
    Else
        MessageBox.Show("没有找到包含关键字的文档","关键字文档查找",MessageBoxButtons.OK,MessageBoxIcon.None)
    End If
    app.Visible = True
catch ex As exception
    msgbox(ex.message)
    app.Quit
finally
End try

 

想自动统计出包含关键字文档的数量,怎么统计呢?count这块该怎么改?

        MessageBox.Show("共计找到包含关键字的文档有count个,目录如下:" & vbcrlf & s,"关键字文档查找",MessageBoxButtons.OK,MessageBoxIcon.None)