Win a copy of Kotlin Cookbook this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Open Word application or Excel App from Java app.

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi You All,
Can someone please tell me how to open a word application or an Excel application for that matter from a java application and also open the file specified when the application opens automatically. Thanx in advance
Bhaskar
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhaskar,
Its not possible to write code to do this in java natively (i am open to contrary opinion). The available avenue for you to do this is to do the following:
1. Write a DLL using platform specific compiler that carries out the opening of the file (use VB, VC++, etc) using a simple function name.
2. Create a java class within your application that defines the 'simple function name' defined above as a 'static native' method, and call java.lang.System.loadLibrary(String) ( probably from within a static initializer block) specifying the DLL filepath/name above to cause the DLL to be loaded into the java process space.
This in effect will link up you java application to call the system specific DLL to render the service you desire. This is the way most developers do it.
Akanimo.
[This message has been edited by Akanimo Udoh (edited July 12, 2001).]
 
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
windows only!!
you can open every file with its associated application by calling the 'start' command.
try on cmd prompt: start somewordfile.doc
this opens somewordfile.doc in word.
you can run this trough Runtime.exec(String cmd)

karl
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Here is the sample code.

Runtime r = Runtime.getRuntime();
r.exec("d:\\Program Files\\Microsoft Office 2000\\Office\\Winword.exe h:\\ADDRESS.doc");

Hope this helps.
Vishal Shah
-----------
SCJP2
-----------
 
Bhaskar Selvaraju
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,
Thanks Guys, You blokes are "BEAUTIFUL" . Thanks so much for this help, makes life so much easier for me.
Thanx once again,
Bhaskar
 
Akanimo Udoh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems I learn something new from javaranch everyday!!!
My thanx too guys for the enlightenment!
Akanimo.
 
They weren't very bright, but they were very, very big. Ad contrast:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!