.NET - A way to add my own clipboard format to existing formats
Posted
by A9S6
on Stack Overflow
See other posts from Stack Overflow
or by A9S6
Published on 2010-02-03T08:05:52Z
Indexed on
2010/05/07
1:18 UTC
Read the original article
Hit count: 365
I have a Excel addin that displays some structures on the worksheet. Users can copy the structures and paste them in another worksheet or another application which is handled by the Clipboard formats. When a user copies the structure, I convert the structure into a specific format and put it on the clipboard using the DataObject::SetData(). Please note that when a copy is initiated in Excel, it puts a number of formats on the clipboard (see image).
The problem is that there is a third party application that depends on the data on the clipboard(Copy from Excel and paste into this 3rd party app) but the funny thing is that I am not sure which format it depends on. I need to preserve the existing formats that Excel has put up there and also add my own format to it.
Currently when I use the Clipboard class in .NET (taking the DataObject and calling SetData inside it), all the other formats are replaced by new ones. I then tried to create a new DataObject, copy the existing format data to this data object and then set this data object in the Clipboard. This works fine but it takes time to copy the data.
// Copying existing data in clipboard to our new DataObject
IDataObject existingDataObject = Clipboard.GetDataObject();
DataObject dataObject = new DataObject();
string[] existingFormats = existingDataObject.GetFormats();
foreach (string existingFormat in existingFormats)
dataObject.SetData(existingFormat, existingDataObject.GetData(existingFormat));
I am looking for a solution to just access the existing DataObject and quietly add my own data to it without affecting other formats.
Excel Clipboard Formats - (Ignore the Native Format)
© Stack Overflow or respective owner