none
What is wrong with these 3 lines of "Clipboard Paste" code? RRS feed

  • Question

  • I have 2 applications: one is based on a WPF DataGrid and the other is an Excel AddIn.

    My goal is to pass data, via Clipboard, from the former to the latter.

    I have no problem copying tab-separated, cuadriculated data into the regular Excel "Paste" operation. Additionally, I implemented my own "Smart Paste".

    My trouble began when I decided to copy+paste a more complex object. I marked all my classes as [Serializable] and have a method that makes sure that the object can be serialized. In fact, the whole operation works perfectly provided that the pasting app is NOT the Excel AddIn.

    The passed object is of a class named Engineering.Export.Exported. As we can see, the clipboard looks fine:

    See the 3 relevant statements. They are identical in both applications.

    The last assignment fails only in the application where I need it.

    I have tried many combinations, for instance GetData("ExportFormat") but the result is the same.

    Any tips, suggestions are very welcome.

    TIA


    Sunday, November 30, 2014 8:00 PM

All replies

  • Hello,

    I am moving this thread to the Excel for Developer forum, see if those there can shed some light on this.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Sunday, November 30, 2014 9:35 PM
  • Hello,

    I am moving this thread to the Excel for Developer forum, see if those there can shed some light on this.


    By doing so, you are converting the possibility of a solution from remote to impossible.

    Monday, December 1, 2014 12:26 AM
  • Hello,

    I am moving this thread to the Excel for Developer forum, see if those there can shed some light on this.


    By doing so, you are converting the possibility of a solution from remote to impossible.

    If you think this is a fact by all means let's hear how you came up with this.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Monday, December 1, 2014 1:17 AM
  • Hi Travis,

    >> The pasted object is of a class named Engineering.Export.Exported. As we can see, the clipboard looks fine

    Where did you declare the “Engineering.Export.Exported” Class?

    I’m trying to reproduce your issue on my side but failed.

    First, creating a class library named “ClassLibrary1” to declare “Customer” Class.

    Second, ctreating a VSTO Excel project “ExcelAddIn1” and adding “ClassLibrary1” to references.

    Then, creating a WPF project “WpfApplication1” and adding “ClassLibrary1” to references also.

    In WPF application, setting the data object;

    In Excel add-in, getting the data object (success).

    namespace ClassLibrary1
    {
        [Serializable]
        public class Customer
        {
            private string nameValue = string.Empty;
            public Customer(String name)
            {
                nameValue = name;
            }
            public string Name
            {
                get { return nameValue; }
                set { nameValue = value; }
            }
        }
    }

    WPF:

            private void CopyButton_Click(object sender, RoutedEventArgs e)
            {
                Clipboard.SetData("CustomerFormat", new Customer("Customer Name"));
            }
    

    Excel Add-in:
            public void On_ButtonClick(Office.IRibbonControl control)
            {
                if (Clipboard.ContainsData("CustomerFormat"))
                {
                    var obj = Clipboard.GetData("CustomerFormat") as Customer;
                }
            }

    Please let me know if I miss any steps, and if it is possible, would you mind providing us a sample project to help us reproduce this issue?

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 2, 2014 2:15 AM
    Moderator