Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-28-2011, 12:50 PM   PM User | #1
Lakshmibp
New to the CF scene

 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Lakshmibp is an unknown quantity at this point
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
Lakshmibp is offline   Reply With Quote
Old 12-28-2011, 01:16 PM   PM User | #2
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
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 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Old 12-28-2011, 01:42 PM   PM User | #3
Lakshmibp
New to the CF scene

 
Join Date: Dec 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Lakshmibp is an unknown quantity at this point
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.
Lakshmibp is offline   Reply With Quote
Old 12-28-2011, 02:06 PM   PM User | #4
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
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 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Old 12-28-2011, 07:20 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 12-28-2011, 07:22 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 12-29-2011, 06:42 AM   PM User | #7
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
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 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Old 12-29-2011, 08:34 PM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 12-30-2011, 04:55 AM   PM User | #9
phpguy
New to the CF scene

 
Join Date: Dec 2011
Location: USA
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
phpguy is an unknown quantity at this point
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.
phpguy is offline   Reply With Quote
Old 12-30-2011, 06:44 AM   PM User | #10
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
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


Quote:
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.
__________________
Regards, R.J.

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

Help spread the word! Like my YouTube-to-Mp3 Web Conversion Software on Facebook !! :)

Last edited by chump2877; 12-30-2011 at 07:01 AM..
chump2877 is offline   Reply With Quote
Old 12-30-2011, 08:08 AM   PM User | #11
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 12-30-2011, 08:14 AM   PM User | #12
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
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 Web Conversion Software on Facebook !! :)
chump2877 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:19 AM.


Advertisement
Log in to turn off these ads.