Showing posts with label from Java. Show all posts
Showing posts with label from Java. Show all posts

Thursday, November 22, 2007

Execute Excel Macros from Java application

We are developing a Java Web application and one of our project features require an excel document to be opened over web page. Once the page (with excel) gets opened a macro should be run automatically and a chart should be shown to user.


Best Solution:
~~~~ ~~~~~~~~
since excel macro is vb code, since we can make a vb script file called from java and it calls excel macro
Example:
make a script file as content is
Dim objXL
Set objXL = CreateObject("Excel.Application")
With objXL
.Workbooks.Open ("File_Path")
.Application.Run "Macro_Name"
.Application.Quit
End With
Set objXL = Nothing
and save it as calling.vbs
in java you can call it as Runtime.getRuntime().exec("cmd /c start calling.vbs");