Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic search for a stirng in word doumnets using javascript

    Requirement:

    In one folder for ex: C:\NewFolder , I have so many word documents in this folder. Now what I have to do is, need to search for any string and it should search for that string in all documents inside that folder and should show output as the name of the docs where it found (same like windows search output) and i should be able to open those docs.

    I want to do this using Javascript. I'm new to javascripting.

    Kindly help me

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Wouldn't something like this be easier than writing your own code to do this: http://answers.microsoft.com/en-us/w...2-bb920efa4f30
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by chump2877 View Post
    Wouldn't something like this be easier than writing your own code to do this: http://answers.microsoft.com/en-us/w...2-bb920efa4f30



    Hi,
    thanks for your reply.... Here what i'm doing is storing all incident reports in another page written in javascript... so i want this in javascript only.
    plz help me.

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    I imagine you could write/run some Windows Scripting Host (WSH) to open up all the docs in a directory and search for text in those docs. But I'm not sure that you could run that in IE with the default security settings. So you'd be better off just double clicking the JS file in your local OS, and running it from there. But if you go that route, how should the results of the search be presented to you (if not in a browser, then where?)
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Well, anything you could do from WSH you should be able to do from the browser. Yes, you have security issues. Even if you run this via the inTRAnet, which you should, MSIE will ask you to allow the "unsafe scripting", but assuming that isn't too annoying and assuming you say "allow", then it will work the same as WSH but give you the opportunity to present the data in the browser.

    Naturally, this only works with MSIE, as you have to instantiate the Word DLL as an ActiveX object.

    The hard part, whether from browser or WSH, is learning all the ActiveX methods and properties that you will need to manipulate Word from scripting.

    Because the docs for Word are written for VBA (Visual Basic for Applications...the language used internal to Word), you are likely to find it easier to translate them from VBA to VBScript, so you might want to consider using VBScript in the browser for all of this.

    It's not a trivial task. But neither is it rocket science. It's just a lot (and I do mean a lot) of sometimes non-obvious operations that you must script. Perusing the VBA docs for Word is the best place to start.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    And this really isn't a task for someone new to scripting. Especially if you insist on using JavaScript so that you have to translate all the VBA docs to JavaScript equivalents.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Seems to me that this would be easiest accomplished with some C# and ASP.NET. Like VB and VBScript, these technologies were made for Windows; in my opinion, C# is superior to VB, VBScript, or JScript; and .NET should expose all the Windows objects, methods, and properties that you need.

    And there should be no issues mixing your existing JS with C# and ASP.NET.

    But to continue programming all of that in JS seems like a chore, as Old Pedant said. The only thing worse than using JS for what you are doing is to write a .bat file or something, lol
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Actually, the only interface that is defined for Word is indeed the ActiveX interface, using the Word.dll library. And the only documentation for the API is given for VBA. (As I said, Visual Basic for Applications--VBA--is the language used internally by Word [and PowerPoint and Excel and Access].)

    So strange as it seems, the best language to "script" Word in is VBScript. It's not a perfect match for VBA. VBA allows typed variables, so you can (example) do Dim doc As Word.Document whereas in VBScript you would just do Dim doc. But then in either case, you might follow up with Set doc = New Word.Document() so once you have the objects dimensioned and initialized, the subsequent code should be identical or nearly so.

    And, yes, I do think this is better accomplished using WSH. But of course WSH can use VBScript as the scripting language just as well (and in a few cases better than) JScript.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    New to the CF scene
    Join Date
    Dec 2011
    Location
    USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use a server side language this isn't a task for java script. There are lots of librarys out there for reading word documents. I guess if you really wanted the info in java script you could use ajax, read the doc spit something back.

  • #10
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    You absolutely can perform a search in Word documents with .NET (and C# -- or VB, or even JScript!) using the Microsoft.Office.Interop.Word namespace: http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

    See also:

    http://msdn.microsoft.com/en-us/libr...(v=VS.80).aspx
    http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx


    Edit: So if you open up each of your Word documents in your directory and run a Microsoft.Office.Interop.Word.Find.Execute, then it will return a boolean value indicating if the search term was or was not found.

    So with .NET, all you have to do is iterate through the contents of the directory, open each word document, do a Find.Execute, and then return the doc names that returned true to the browser window. Seems pretty straightforward.
    Last edited by chump2877; 12-30-2011 at 07:01 AM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Well, shows how out of date I am!

    Last time I looked for something like this was indeed in 2001 or 2002 and the interop libraries didn't exist at that time. (Happened to be a project where I needed to script Excel, but the interop is conceptually the same for both.)

    So I 100% agree with you. This is by far the best and easiest way to do the task.

    Assuming that the documents to be searched are on the server, there's no excuse for using anything else.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #12
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Also, if he's not using an independent web server, he could install IIS on his local Windows machine. Then everything could be done locally.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •