Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Tuomo  is currently offline Tuomo Friend
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 Very Happy

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 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
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.
>
Re: OLE embedding and paste automation for Word [message #495205 is a reply to message #494744] Wed, 04 November 2009 07:39 Go to previous messageGo to next message
Tuomo  is currently offline Tuomo Friend
Messages: 2
Registered: November 2009
Junior Member

Thank you Grant!

Now it is working nicely.

Regards,

Tuomo
Re: OLE embedding and paste automation for Word [message #495310 is a reply to message #495205] Wed, 04 November 2009 14:46 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
I just noticed one small problem in the lines I provided:
"selection.invoke(ids[0]);" should become "result =
selection.invoke(ids[0]); result.dispose();"

Grant


"Tuomo" <thyyryla@cc.hut.fi> wrote in message
news:hcrb4f$t94$1@build.eclipse.org...
>
> Thank you Grant!
>
> Now it is working nicely.
>
> Regards,
>
> Tuomo
>
Re: OLE embedding and paste automation for Word [message #498111 is a reply to message #495310] Sat, 14 November 2009 15:37 Go to previous messageGo to next message
Vincenzo Caselli is currently offline Vincenzo CaselliFriend
Messages: 51
Registered: July 2009
Member
Hi Grant,
I also want to thank you. I was looking for the Paste operation, but encountered the same problems reported by Tuomo. So your answer was very welcome.
Still, now I am trying to make the "SelectAll", then "Copy" operation, (still with Word ActiveX) but I am not able to do it.
Do you have the solution also for this? Anyway in these situations, where can we find documentation on how to do these common operation?
Thank you in advance
Vincenzo Caselli
Re: OLE embedding and paste automation for Word [message #498354 is a reply to message #498111] Mon, 16 November 2009 14:50 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Vincenzo,

The documentation on MSDN is generally pretty good. The links that are
applicable to these cases are:

Document: http://msdn.microsoft.com/en-us/library/bb257531.aspx
Application: http://msdn.microsoft.com/en-us/library/bb244569.aspx
Selection: http://msdn.microsoft.com/en-us/library/bb259574.aspx

To do the select all I think you invoke Document.Select(), and to do the
copy invoke Selection.Copy().

Grant


"Vincenzo Caselli" <v.caselli@rcp-vision.com> wrote in message
news:hdmiqu$8ib$1@build.eclipse.org...
> Hi Grant,
> I also want to thank you. I was looking for the Paste operation, but
encountered the same problems reported by Tuomo. So your answer was very
welcome.
> Still, now I am trying to make the "SelectAll", then "Copy" operation,
(still with Word ActiveX) but I am not able to do it.
> Do you have the solution also for this? Anyway in these situations, where
can we find documentation on how to do these common operation?
> Thank you in advance
> Vincenzo Caselli
Re: OLE embedding and paste automation for Word [message #508700 is a reply to message #498354] Tue, 19 January 2010 22:05 Go to previous messageGo to next message
Vincenzo Caselli is currently offline Vincenzo CaselliFriend
Messages: 51
Registered: July 2009
Member
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
Re: OLE embedding and paste automation for Word [message #509902 is a reply to message #508700] Mon, 25 January 2010 17:20 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
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
>
Previous Topic:FormLayout and child relative height
Next Topic:Let JAWS Reads Line numbers
Goto Forum:
  


Current Time: Sat Dec 14 14:41:47 GMT 2024

Powered by FUDForum. Page generated in 0.04567 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top