Results 1 to 13 of 13
  1. #1
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Using Office Automation from Java

    This is not at all a VB question, but the VB/VBA forum seems to be the most likely place to find programmers! :-)

    I am writing a Java application that needs to give some commands to Word and get back results. It appears that the straightforward way to do this would be to use Office Automation -- that is, address Word as an ActiveX control -- through an appropriate Java class.

    I've combed the Web for such a tool, and I can't find one. Does anyone know of anything?

    Microsoft offers what I need in J++, but I happen to own and be accustomed to a different development platform. Should I have to pay several hundred dollars for a new tool, then invest several weeks in learning to use it effectively? What if my application needs to perform some other task that's supported only by some other particular tool? I don't want to go down that road.

    Sun offers an "ActiveX Bridge" which is now integrated into the standard Java Developer's Kit, but it only appears to let JavaBeans function as ActiveX controls. That's a useful and honorable function, but it's the opposite of what I need.

    Last year somebody inquired in Sun's Java developers' forum about how to use an ActiveX control from a Java application, and no one answered.

    I can buy a Java/DDE interface product that will do the job, but I think that DDE was already an obsolescent technology when Java was introduced! Why is it apparently the only available solution to what seems like a pretty obvious problem?

    All of this looks fishy, like some big part of the puzzle is missing. Is it?

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Marietta, Georgia, USA
    Posts
    296
    Thanks
    9
    Thanked 4 Times in 4 Posts

    Re: Using Office Automation from Java

    It makes sense to me that you can't find a generic solution. Java is supposed to be platform-agnostic - but ActiveX controls are M$ Windows specific.

    It also makes sense that the only solution is to use M$ J++, since Microsoft added in the "plumbing" to communicate with their ActiveX technology.
    Rick Groszkiewicz
    Life is too short to drink bad wine (or bad coffee!)

  3. #3
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Using Office Automation from Java

    I'm trying to elicit suggestions for solving a problem -- either leads to the missing piece of the puzzle, or suggestions for other routes to my goal. I'm sure you'll appreciate that getting reasons why the problem should be impossible to solve does not strike me as nearly so useful.

    Since you raise these points, though, I'll respond to them.

    You're quite correct that Java is supposed to be platform-agnostic. That means that it should impose no artificial restrictions on the developer's ability to create any type of software for use on every possible platform. It does not follow that if solving a particular problem on a particular platform requires use of platform-specific features, Java should be incapable of supporting them. That is not "platform-agnostic"; that is crippled.

    You're half correct that ActiveX controls are Windows-specific. They run only under Windows, but the ActiveX architecture was designed from the ground up to produce software that is accessible from any platform. That fits the Java philosophy perfectly.

    As I pointed out in the original post, Sun has offered a Java-ActiveX bridge for years, and somewhere around JDK 1.3 they incorporated it into the JDK itself -- a rather remarkable acknowledgment of the importance of ActiveX technology in the Java world. Problem is, they apparently solved only half the problem: letting the world call JavaBeans as if they were ActiveX controls. For me the ActiveX control is a given; the Java application needs to be able to call it as if it were a JavaBean.

    So the question is not, "Why doesn't Java have ActiveX support?" The question is, "Where's the other half?"

    The very existence of the Java-ActiveX bridge demonstrates that to a substantial extent, ActiveX _functionality_ is itself platform-agnostic. If a JavaBean can be made to behave like an ActiveX control, an ActiveX control could equally well be made to behave like a JavaBean. Thus, even the more restrictive definition of "platform-agnostic" that you proposed does not explain why the tool I need does not exist, if it does not exist.

  4. #4
    Lounger
    Join Date
    May 2001
    Location
    the Netherlands
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Office Automation from Java

    The Jakarta POI project is still working on HWPF - their port of the Word format http://jakarta.apache.org/poi/hwpf/index.html.
    I'd search the Desktop forum at the Sun Java forum http://forum.java.sun.com/index.jspa, you can't be the only one wanting to get to Word from Java!

  5. #5
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Using Office Automation from Java

    Good reference. I'm aware of their work, and it's a valuable resource, but unfortunately not a suitable one for me.

    Being able to read the file would not solve my problem; I have to find out where the page, column, and line breaks fall in the formatted document, and I believe that only Word itself can tell me that with any degree of reliability.

  6. #6
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Using Office Automation from Java

    (Edited by HansV to make URLs clickable - see <!help=19>Help 19<!/help>)

    I found a little more information by searching for "COM" and "DCOM" instead of "ActiveX." I discovered that Microsoft does not distinguish between ActiveX and COM/DCOM in a consistent way, and many other people use the terms interchangeably.

    I found a couple of products that do what I want. Unfortunately, one of them is still in beta and runs only under UNIX. The other is a commercial product, but the web site is coy about pricing; apparently potential customers are supposed to call the friendly sales rep and dicker. I don't have the resources to pay the kind of money that approach implies. (If I did, an expensive licensed component would be a show-stopper for the project in any case.)

    For anyone who is interested, the relevant links are:

    http://www.octatec.co.uk/CB_java_document.htm
    http://j-integra.intrinsyc.com/com/info

    The product in beta looks appallingly primitive from the brief code example on the web site. To call a particular method on a COM object you determine its position in a table produced by the development system that compiled the object, and call it by index. For example, to call WinWord.Documents.Open you might write, "call method 123." (Heaven help you if a new version of the object is installed and the table of methods changes. Perhaps you can write code to find the table indexes at runtime. Since the product won't run on my system anyway, I'm not investigating further.)

    The answer to my question that seems to be emerging is: Microsoft architecture makes COM/DCOM/ActiveX support devilishly difficult to implement, and nobody in the open-source community has taken the trouble. Perhaps the fact that Sun solved half the problem has deterred them, implying that any development work they do is likely to be preempted.

    Unless something unexpected comes up, I'm going to go with DDE after all. It may be old-fashioned and clunky, but it will do what I need, Java support is available, and it's free.

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Using Office Automation from Java

    Plan C might be to add a VBScript file to your application and have it save the information you want to a file. Assuming you're running on Windows and can run any arbitrary program on the PC.

  8. #8
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Office Automation from Java

    reverse engineer java JNI?
    or
    http://j-integra.intrinsyc.com/com/download/

    (you have to contact them though for licencing fees, evaluation period is free.)

  9. #9
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Using Office Automation from Java

    I mentioned j-integra myself earlier in the thread.

    I don't understand what reverse-engineering JNI would accomplish (or even, really, what it would mean). I suppose I could use JNI to call a subroutine written in another language that is ActiveX-capable, but that seems like an inordinately difficult way to solve the problem.

  10. #10
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Using Office Automation from Java

    I am running on a Windows platform, but the possibility of using a VBScript file has not occurred to me. I guess I don't understand enough about how VBScript works, because as far as I know it is just a Windows-centric substitute for JavaScript, and runs only in Microsoft Web browsers or Web servers.

    I looked around the web a little bit, but found no information that would give me a broader perspective. Thus it's not clear to me how my Java application could be made to run a VBScript file. I'll investigate this if you can tell me where to start looking.

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Using Office Automation from Java

    Does the Java security model let you launch an executable from the hard drive? If so, the cscript.exe command interpreter will run either a JavaScript or VBScript file, and either can readily do COM automation. I use VBScript because it's similar to VBA (which I use most often for Office automation) and more tolerant of sloppy capitalization. <img src=/S/blackteeth.gif border=0 alt=blackteeth width=20 height=20>

  12. #12
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Office Automation from Java

    This looks promising:

    http://simtel.net/product.php[url_fb_product_page]60701

    Java is one language I've never programmed in, so I can't try this out, but again, it looks promising.

    Hope this helps!

  13. #13
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Using Office Automation from Java

    Sorry about the long response time; I have been busy with school, and haven't had any time to work on this project.

    >Does the Java security model let you launch an executable from the hard drive?

    Sure, but I don't understand what that would accomplish. I need to make my Java application communicate with an ActiveX control. If I launched a JavaScript or VBScript interpreter and ran a script that started the control, I would then need to make my Java program communicate with the script. It seems to me that this would make the system more complex without solving the problem.

    >This looks promising:
    >http://simtel.net/product.php[url_fb_product_page]60701

    It does indeed. When I have time (after school ends, in about a month, I hope) I will download it and see what it will do for me.

    I would really rather use the COM interface than the DDE interface; it is probably more efficient, and I suspect that it is more reliable.

Posting Permissions

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