How can I copy the entire (all formats) of the clipboard

601 Views Asked by At

We need to copy and re-post what is in the clipboard - all formats. Is there a way to do this?

Here's the use case. We have small docx/pptx/xlsx documents that, in our Office AddIn, we want to enable the user to drag/drop into word/ppt/xl. Unfortunately, the best documented format for this is html which is not that close to the actual docx/pptx/xlsx.

So, my thought is we (using Word as the example) create an instance of a Word Document object (our code is a Word AddIn so by definition Word is running). We then call that Document object to select all of it and then paste the selection.

At this point the clipboard contains that pasted document. Including in the undocumented format Word uses for copy/paste within Word documents. That's the format we want to use.

If we can then copy all of the clipboard contents into an object of ours that implements IDataObject and pass that object to Control.DoDragDrop(), then when the user drops it somewhere in Word, they are giving it to Word in the undocumented format which has all the docx formatting.

Is there a way to do this?

Update: We need to drag/drop the file contents (not just the text, the fully formatted text, tables, shapes, charts, etc.).

Update 2: We need to pass this as an IDataObject to DoDragDrop(), not do a paste from the clipboard. We do not need to be notified when it happens because we've passed the IDataObject to Windows and Windows takes it from there.

1

There are 1 best solutions below

0
On

It turns out there's a call for this - Clipboard.GetDataObject().