• Using Office Automation from Java

    Author
    Topic
    #415249

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #925606

      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.

      • #925801

        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.

        • #925959

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

          • #926011

            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.

            • #926120

              (Edited by HansV to make URLs clickable – see Help 19)

              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%5B/url%5D
              http://j-integra.intrinsyc.com/com/info%5B/url%5D

              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.

            • #929131

              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.

            • #929141

              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.

            • #929349

              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. blackteeth

    • #929263

      reverse engineer java JNI?
      or
      http://j-integra.intrinsyc.com/com/download/%5B/url%5D

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

      • #929328

        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.

        • #931983

          This looks promising:

          60701″]http://simtel.net/product.php%5Burl_fb_product_page%5D60701%5B/url%5D

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

          Hope this helps!

          • #941384

            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.

    Viewing 1 reply thread
    Reply To: Using Office Automation from Java

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: