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 08:41  |
Eclipse User |
|
|
|
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 08:42] by Moderator
|
|
|
Re: OLE embedding and paste automation for Word [message #495058 is a reply to message #494744] |
Tue, 03 November 2009 11:36   |
Eclipse User |
|
|
|
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.
>
|
|
| | | | | |
Re: OLE embedding and paste automation for Word [message #509902 is a reply to message #508700] |
Mon, 25 January 2010 12:20  |
Eclipse User |
|
|
|
If the passing of function arguments is what you're wondering about, you
need to get their ids when getting the function's id, and provide these ids
along with the argument values. This would look like:
ids = selection.getIDsOfNames(new String[] {"EndKey", "Unit"});
int[] argIds = {ids[1]};
Variant[] args = new Variant[1];
args[0] = new Variant(4 /* wdParagraph */);
selection.invoke(ids[0], args, argIds);
args[0].dispose();
selection.dispose();
I did a quick experiment and invoking EndKey didn't have the desired effect
(I have Word 2000 installed, perhaps this works in newer versions?). I'm
sure there's a command somewhere for doing this that can be invoked using an
approach like the one here.
Grant
"Vincenzo Caselli" <v.caselli@rcp-vision.com> wrote in message
news:hj5aah$avv$1@build.eclipse.org...
> Now I would like to go to the end of the document.
> I've read the MS links, but can't understand how to apply the concepts in
Java ...
> It seems that the right command is "EndKey" on the "Selection" object, but
still I am not able to invoke it correctly
> someone can help?
>
> Thanks
> Vincenzo
>
|
|
|
Goto Forum:
Current Time: Sun Jul 06 22:41:31 EDT 2025
Powered by FUDForum. Page generated in 0.05555 seconds
|