Home » Eclipse Projects » Standard Widget Toolkit (SWT) » OLE embedding and paste automation for Word(How to execute "paste" command using swt.ole.win32?)
OLE embedding and paste automation for Word [message #494744] |
Mon, 02 November 2009 13:41 |
Tuomo Messages: 2 Registered: November 2009 |
Junior Member |
|
|
I have successfully used the stuff in org.eclipse.swt.ole.win32 to embed Microsoft Word in a SWT shell. For example (layout, exeption handling etc removed):
Display swtDisplay = new Display();
Shell swtShell = new Shell(swtDisplay);
swtShell.open();
Menu menuBar = new Menu(swtShell, SWT.BAR);
swtShell.setMenuBar(menuBar);
OleFrame oleFrame = new OleFrame(swtShell, SWT.NONE);
OleClientSite site = new OleClientSite(oleFrame, SWT.NONE, "Word.Document");
site.doVerb(org.eclipse.swt.ole.win32.OLE.OLEIVERB_SHOW);
while (!swtShell.isDisposed ()) {
if (!swtDisplay.readAndDispatch()) swtDisplay.sleep ();
}
This works perfectly, with Word (and own "container") menus etc displaying and working correctly. But next I would like to command Word to paste data from clipboard to cursor position. I tried:
if((site.queryStatus(OLE.OLECMDID_PASTE) & OLE.OLECMDF_ENABLED) != 0) {
site.exec(OLE.OLECMDID_PASTE, OLE.OLECMDEXECOPT_DONTPROMPTUSER, null, null);
}
But it seems that OLECMDID_PASTE is neither ENABLED or even SUPPORTED. I went through all the OLECMDIDs, and some of them were ENABLED and worked nicely. None of copy/cut/paste trio did work.
I also tried with Excel, and paste did not work with it either. I have Office 2003.
So, is this a feature of Office programs, or is there a problem with SWT OLE, or am I doing something funny, ...?
Maybe there is an alternative way to do this using OLE Automation, but I could not figure out how to do that.
I got it to "somewhat working state" by using java.awt.Robot to issue ctrl-v key press event, but I'd really like some real solution
So, thank you for any insight.
[Updated on: Mon, 02 November 2009 13:42] Report message to a moderator
|
|
|
Re: OLE embedding and paste automation for Word [message #495058 is a reply to message #494744] |
Tue, 03 November 2009 16:36 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi,
I don't know why queryStatus(...) is answering 0, but if it's giving other
results for other commands then presumably it's working in swt, and for some
reason Word just doesn't want Paste to be invoked this way. This can be
done with OLE Automation instead, the lines you need are:
OleAutomation document = new OleAutomation(clientSite);
int[] ids = document.getIDsOfNames(new String[] {"Application"});
Variant result = document.getProperty(ids[0]);
document.dispose();
OleAutomation application = result.getAutomation();
result.dispose();
ids = application.getIDsOfNames(new String[] {"Selection"});
result = application.getProperty(ids[0]);
application.dispose();
OleAutomation selection = result.getAutomation();
result.dispose();
ids = selection.getIDsOfNames(new String[] {"Paste"});
selection.invoke(ids[0]);
selection.dispose();
Grant
"Tuomo" <thyyryla@cc.hut.fi> wrote in message
news:hcmnht$180$1@build.eclipse.org...
> I have successfully used the stuff in org.eclipse.swt.ole.win32 to embed
Microsoft Word in a SWT shell. For example (layout, exeption handling etc
removed):
>
>
> Display swtDisplay = new Display();
> Shell swtShell = new Shell(swtDisplay);
> swtShell.open();
>
> Menu menuBar = new Menu(swtShell, SWT.BAR);
> swtShell.setMenuBar(menuBar);
>
> OleFrame oleFrame = new OleFrame(swtShell, SWT.NONE);
> OleClientSite site = new OleClientSite(oleFrame, SWT.NONE,
"Word.Document");
> site.doVerb(org.eclipse.swt.ole.win32.OLE.OLEIVERB_SHOW);
>
> while (!swtShell.isDisposed ()) {
> if (!swtDisplay.readAndDispatch()) swtDisplay.sleep ();
> }
>
>
> This works perfectly, with Word (and own "container") menus etc displaying
and working correctly. But next I would like to command Word to paste data
from clipboard to cursor position. I tried:
>
>
> if((site.queryStatus(OLE.OLECMDID_PASTE) & OLE.OLECMDF_ENABLED) != 0) {
> site.exec(OLE.OLECMDID_PASTE, OLE.OLECMDEXECOPT_DONTPROMPTUSER, null,
null);
> }
>
>
> But it seems that OLECMDID_PASTE is neither ENABLED or even SUPPORTED. I
went through all the OLECMDIDs, and some of them were ENABLED and worked
nicely. None of copy/cur/paste trio did work.
>
> I also tried with Excel, and paste did not work with it either. I have
Office 2003.
>
> So, is this a feature of Office programs, or is there a problem with SWT
OLE, or am I doing something funny, ...?
>
> Maybe there is an alternative way to do this using OLE Automation, but I
could not figure out how to do that.
>
> I got it to "somewhat working state" by using java.awt.Robot to issue
ctrl-v key press event, but I'd really like some real solution :d
>
> So, thank you for any insight.
>
|
|
| | | | | | |
Goto Forum:
Current Time: Sat Dec 14 14:41:47 GMT 2024
Powered by FUDForum. Page generated in 0.04567 seconds
|