Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbedding Office in Java
    primarykey
    data
    text
    <p>I'm trying to get Office 2007/2010 application embedded inside a Java application using SWT using the following code:</p> <pre><code>import java.awt.Canvas; import javax.swing.JFrame; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.ole.win32.*; import org.eclipse.swt.widgets.*; public class EmbeddingTest extends Canvas { private void initOleViewer(String target) { Display display = new Display(); Shell shell = SWT_AWT.new_Shell(display, this); shell.setLayout(new FillLayout()); OleFrame oleFrame = new OleFrame(shell, SWT.NONE); OleControlSite oleControlSite = new OleControlSite(oleFrame, SWT.NONE, "Word.Document"); oleControlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); OleAutomation word = new OleAutomation(oleControlSite); int[] applicationId = word.getIDsOfNames(new String[]{"Application"}); Variant property = word.getProperty(applicationId[0]); OleAutomation application = property.getAutomation(); int[] documentId = application.getIDsOfNames(new String[]{"Documents"}); property = application.getProperty(documentId[0]); OleAutomation documents = property.getAutomation(); shell.open(); Variant[] arguments = new Variant[] { new Variant(target) }; int[] automationIDs = documents.getIDsOfNames(new String[]{"Open", "FileName"}); documents.invokeNoReply(automationIDs[0], arguments, new int[]{automationIDs[1]}); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } public static void main(String[] args) { JFrame jFrame = new JFrame("Embedding Test"); jFrame.setVisible(true); EmbeddingTest viewer = new EmbeddingTest(); jFrame.add(viewer); jFrame.setSize(600, 600); viewer.initOleViewer(args[0]); } } </code></pre> <p>When I don't try to call 'Open' on the document object Word embeds successfully inside the application but the whole file menu is disabled. When I call 'Open' the application crashes with the following error (DISP_E_EXCEPTION):</p> <blockquote> <pre><code>Exception in thread "main" org.eclipse.swt.SWTException: Action can not be performed. result = -2147352567 at org.eclipse.swt.ole.win32.OLE.error(Unknown Source) at org.eclipse.swt.ole.win32.OleAutomation.invokeNoReply(Unknown Source) at EmbeddingTest.initOleViewer(EmbeddingTest.java:68) at EmbeddingTest.main(EmbeddingTest.java:88) </code></pre> </blockquote> <h3>Does anyone know how to fix this problem or an alternative solution to embed Office apps in Java? Thanks!</h3> <p><br/> <hr/></p> <h3>Update:</h3> <p>Querying the IDs for 'Open' and 'FileName' separately returns null for 'FileName' so its incorrect. I've also tried without the named parameter without any success:</p> <pre><code>documents.invokeNoReply(automationIDs[0], arguments); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload