excel - .NET - A way to add my own clipboard format to existing formats -
I have an Excel addin that shows some structure on the worksheet. Users can copy the formations and paste them into another worksheet or another application that is controlled by clipboard formats. When a user copies the structure, then I convert the structure to a specific format and keep it on the clipboard using DataObject :: SetData (). Please note that when the copy is started in Excel, it will put several 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 it into this third party app) but the funny thing is that I am not sure how this format depends. . I need to preserve the existing formats that Excel has placed there and also add its own format for it.
Currently when I use the clipboard class in .NET (which takes DataObject and the set data inside it), all the other formats are replaced by new ones, then I create a new data object Tried, copy the current form data into this data object and then set this data object in the clipboard. It works fine, but it takes time to copy the data.
// Existing data in the clipboard to create our new data object ID to embed the existing objectDatabase object = clipboard. GetDataObject (); Data object dataobject = new datable object (); String [] Existing Formats = Existing Data Object GetFormats (); Foreign exchange (existing formats existing in existing formats) Data object. Setdata (existing format, existing datatyagate .adata (current format));
I'm just looking for a solution to use existing data objects and add my own data silently without affecting other formats.
Excel clipboard format - (ignore the original format)
A wrapper class for an IDTabage you get from the Windows clipboard to add your data. The idea is that the cover will be aware of your custom formats and will represent the original, wrapped IDataObject for all other formats.
Here is a partial implementation that is showing to the Creator and one of the IDATObject method implementations:
Public class MyDataObject: IDataObject {public MyDataObject (IDataObject internal, string format , Type type, object data) {m_inner = inner; M_format = format; M_type = type; M_data = Data; } Private IDataObject m_inner; Private string m_format; Private type m_type; Private object m_data; Object IDataObject.GetData (string format) {// If I have a format, return wrapper data if (format == m_format) returns object; // Otherwise, Assign the wrapped data object which / / other format returns m_inner.GetData (format); } // Apply the rest of IDotabage in the same way ...}
A warning: When retrieving the system clipboard IDataObject, you will need to see whether it is in your wrapper items One is from In that case, you do not want to wrap your rapper instead, instead you want to modify the data / format fields of the current cover, or want to create a new cover for the original clipboard data object.
Comments
Post a Comment