GeeCON Prague 2014*
The moose likes Other JSE/JEE APIs and the fly likes Problem with Ms Word Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Problem with Ms Word" Watch "Problem with Ms Word" New topic
Author

Problem with Ms Word

Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi All,
I want to run the macro of the ms word docs on the click of the button. And in that I want to auto enable the macros.

Please suggest me the way to do it with the help of Java.

Thanks
Kushagra Bindal
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
Is this a button in Word itself or in a Java application? If the former, no Java is necessary because you can attach the macro directly to the button. If the latter, then that's not possible using just Java.


Ping & DNS - my free Android networking tools app
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi ,
Actually in my scenario I am working on the swing application and using the browser window with the help of Java application of the Swing itself.

And on the click of Open button I select few ms word file and want to process on that. And there are macro in the word files. So in my scenario I want my Java Swing application will enable the macro every time automatically. As I don't want users to do the same every time.

So there are two way.
1. Enable the macro
2. Make the setting of the macro as low but in that case it will be treated as virus in many case.

So please suggest me the possible solution.

Thanks
Kushagra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
I'm still partly confused (not sure what "the browser window" has to do with a Java application handling Word documents, and I don't understand #2 at all), but it seems to boil down to selecting a DOC file in a Swing application and then making some particular macro in that DOC file an auto-run macro. Is that about right?

I don't think Apache POI -which is the major Word API in Java- has the capability to handle macros on this level. Maybe OpenOffice (which has a Java API) can do this.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi,

Browser Window means when you will open some file from some editor it will ask you to open it from some location and give you a small window that have two button of open and cancel. The same window I have from where I select few word file to process as I had to do some processing on that. May be POI is not able to handle the same but is there a simple way in Java to handle the same thing or to run the macro with macro enable by default.

Thanks
Kushagra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
In order to run macros you need either Word or OpenOffice (IF that can handle Word macros). OO has a Java API, while Word doesn't, so you'd need JNI code that calls some COM component to invoke Word. Either way, it's not going to be easy.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi,


As per the present condition is there a way by which I can process on the ms word file. As might be you remember that we already have a discussion the same. That I want to read the actual/running word count of the ms word. But the problem is that from Java end we can only read it through its property. So I am in process of discovering a possible way.
But user are mainly of mac.

As per the above mention condition we have following option.
1. Apply JNI(But it will create problem of C++ guy to work on mac)
2. Work with macro(From Java side not easy to enable the macro or what we can do is to lower down the registry setting of word for window but this is not required for mac user).
3. To run a batch/apple script.


So what I was planning from the above all option is that to open the word document and then set the running word count in its custom properties from where I can easily read the count. And that is correct as we know that there are lot of discripencies in the properties word count and running word count.

Now please suggest me the possible way to proceed.

Thanks
Kushagra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
I don't recall all the details of that previous discussion; didn't you want to write your own word count and store that in a document property? What became of that?
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Ok not a probs.

No I don't want to write my own word count. Actually in word scenario word count for the properties and the that for the word when it actually get open is different.
You can also confirm it from opening it from on your machine.

In First scene you can get it from summary properties and in the second case you can open the docs and go to the tools---> word Count. Now here you can see that there are changes upto 1000 word for a file of having word count of 10000. Isn't it too big to consider. So thats why I want all of the activity to perform my task in more clear way and that will help of my user to detect the changes.

Thanks
Kushagra
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi All,
If any body is having the solution for that please suggest me for the same. It is not necessary to handle it via poi if anything is having the solution to handle the same probelm please help me in that.

Thanks
Kushagra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
I think it would help if you stated what EXACTLY the underlying problem is at this point. This discussion is kind of all over place, ranging from macros to document properties to JNI to word counts, and I for one have lost track of what the original issue is that you were trying to address with all this.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi,
Let me explain you.

Actually my prime target is to calculate the word count of Ms Word.

So for that I tried first to use BufferedStream. But that was giving the wrong word count.
Then I switch my approach to POI and try to calculate the word count through it but at the same POI is only able to read the word count from its summary properties(doc header). So my problem won't solve. So then I tried to open the word doc and then try to run macro on it by placing it in STARTUP folder so that at the time of open it will set latest(real) word count in the custom properties and from where I can read the word count with the help of POI. But it is also not a good solution. So at last I am trying now to apply some other interface by which I can calculate the word count effectively.

So the whoe problem was due to word count.


Any suggestion rwgarding the same.

Thanks
Kushagra
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
If the word count that Word itself provides in the document property is incorrect according to your requirements, then my advice is the same I've given in some other thread: write your own using the POI API. See "Basic Text Extraction" and "Specific Text Extraction" in http://poi.apache.org/hwpf/quick-guide.html for some starting points.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi,

I have used the same but getText()

It working fine for plain document. But for the text having index, table, images it generate the string with the extra words and don't know due to what. It include the toc tag for index and sort of situation coming.

Now in the same case what I need to do.

Please suggest me the possible way to do the same.

Thanks
Kushagra
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi All,

I am a newbie to JNI and according to my client it will be ok to use JNI in window and apply different approach in Mac OS.

So by using JNI I want to read now the word count of the word. Please suggest me the possible to proceed.

Thanks
Kushagra

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

For JNI itself you should start with http://java.sun.com/j2se/1.4.2/docs/guide/jni/

For the native code itself, I think you will have more success on Microsoft's MSDN forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: Problem with Ms Word