Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to use Word.Application, because Word.Document will not let you use automation features, this is my experience at least. When I implemented automation and Ole I did it in 2 steps. </p> <ol> <li>Opened word document in automation mode (Word.Application), didsome automation tasks and closed</li> <li>Opened word document as Word.Document. Automation tasks did not work, but it was an OLE object. User can edit document, but save options are disabled. You can however add extra menu and do something like Ole.Save. Then captured document can be processed furter.</li> </ol> <p>Here you find example of how to open document in <strong>Word.Application</strong>. Then according to my experience you should save it and open in OLE as <strong>Word.Document</strong>. Showing Word.Application can be skipped.</p> <pre><code>import java.awt.Canvas; import javax.swing.JFrame; import org.eclipse.swt.SWT; 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 = new Shell(display); OleFrame oleFrame = new OleFrame(shell, SWT.NONE); OleClientSite oleClientSite = new OleClientSite(oleFrame, SWT.NONE, "Word.Application"); OleAutomation word = new OleAutomation(oleClientSite); Variant[] arguments; //open the file int[] id1 = word.getIDsOfNames(new String[]{"Documents"}); Variant pVarResult = word.getProperty(id1[0]); OleAutomation resultDocuments = pVarResult.getAutomation(); int[] id2 = resultDocuments.getIDsOfNames(new String[]{"Open"}); arguments = new Variant[1]; arguments[0] = new Variant(target); Variant invokeResult = resultDocuments.invoke(id2[0], arguments); resultDocuments.getIDsOfNames(new String[]{"ActiveDocument"}); //show the word app, not necessary arguments=new Variant[1]; arguments[0] = new Variant(true); int[] id3 = word.getIDsOfNames(new String[]{"Visible"}); word.setProperty(id3[0], arguments); 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("d:\\aaa.doc"); } } </code></pre>
 

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