copying word document to clipboard

Add-in Express™ Support Service
That's what is more important than anything else

copying word document to clipboard
 
Guest


Guest


i am trying to develop word add-in which copies the active document to the clipboard in rtf format.

c# or vb.net is ok.

thanks in advance,
serhat.
Posted 12 Mar, 2005 14:51:22 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Serhat.

You can put the content of Word document to the clipboard with three line of the code:

Word._Document doc = WordApp.ActiveDocument;
doc.Select();
WordApp.Selection.Copy();
Posted 14 Mar, 2005 04:12:42 Top
Guest


Guest


thanks a lot sergey,
but how about putting it directly in to a DataObject?
Is it possible?

if not, how can i remove it from word's office clipboard after i am done with it?

thanks,
serhat.
Posted 17 Mar, 2005 15:42:03 Top
Guest


Guest


i think i was not clear enough,

how can i put rtf of a document in to a dataobject directly, without using clipboard?

thanks.
Posted 17 Mar, 2005 15:42:58 Top
Eugene Starostin


ADX Team
Add-in Express team


Posts: 430
Joined: 2004-04-05
Have a look at this topic
Posted 18 Mar, 2005 09:08:46 Top
Guest


Guest


i checked the topic, but i think i missed the point.
I couldnt see any reply which helps me to put the content of an active document directly to a dataobject using .NET
Posted 18 Mar, 2005 18:22:09 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Serhat.

I rewrote the Delphi code in C#. See below.

[DllImport("ole32.dll", CharSet=CharSet.Auto)]
public static extern int OleSetClipboard(IDataObject pDataObj);

private void adxCommandBarButton4_Click(object sender)
{
if (WordApp.Documents.Count > 0)
{
IntPtr unk = IntPtr.Zero;
IntPtr docUnk = Marshal.GetIUnknownForObject (WordApp.ActiveDocument);
try
{
Guid g = typeof(IDataObject).GUID;
Marshal.QueryInterface(docUnk, ref g, out unk);
if (unk != IntPtr.Zero)
{
IDataObject data = WordApp.ActiveDocument as IDataObject;
OleSetClipboard(data);
}
}
finally
{
if (docUnk != IntPtr.Zero)
Marshal.Release(docUnk);
if (unk != IntPtr.Zero)
Marshal.Release(unk);
}
}
}

[ComImport, ComVisible(false),
GuidAttribute("0000010E-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDataObject
{
int GetData(IntPtr formatetcIn, out IntPtr medium);
int GetDataHere(IntPtr formatetc, out IntPtr medium);
int QueryGetData(IntPtr formatetc);
int GetCanonicalFormatEtc(IntPtr formatetc, out IntPtr formatetcOut);
int SetData(IntPtr formatetc, ref IntPtr medium, bool fRelease);
int EnumFormatEtc(int dwDirection, out IntPtr enumFormatEtc);
int DAdvise(IntPtr formatetc, int advf, IntPtr advSink, out int dwConnection);
int DUnadvise(int dwConnection);
int EnumDAdvise(out IntPtr enumAdvise);
}
Posted 19 Mar, 2005 17:05:20 Top
Guest


Guest


thank you very much for your efforts sergey,
i will try it now.

regards,
serhat.
Posted 20 Mar, 2005 04:17:44 Top
Guest


Guest


that was exactly what i wanted,
thanks again.

regards,
serhat.
Posted 20 Mar, 2005 04:28:51 Top