none
How to extract the Object from Clipboard in excel 2010 64 bit. RRS feed

  • Question

  • Hi,
    In my application extracting the object(*.m) present in excel 2003 32 bit is worked by using following code.

    IDataObject iData = Clipboard.GetDataObject();

    if (iData != null)
    {
        string name = iData.ToString();
        string objType = "Native";
        object objToSave = iData.GetData(objType);
    }

    but the same code fails to extract the object present in excel 2010 64 bit in windows 7 64 bit version because "iData.GetData(objType)" returns null.

    How to handle this scenario and extract the object in excel 2010.
    Tuesday, March 25, 2014 5:01 AM

All replies

  • Hello Sathish,

    First or all, please remember that the Excel object model provides the Copy and Paste methods. The latter pastes the contents of the Clipboard onto the sheet.

    What object are you trying to extract? Who did copy the object into the clipboard?

    Are you able to reproduce the issue with a regular standalone windows forms application? Just try to set the target platform to the x64 value. Does it work? Can you extract the object?

    It looks like the issue is not related to VSTO at all. The Clipboard class comes from the .Net base classes and is not related to VSTO (nor Excel).

    Tuesday, March 25, 2014 4:03 PM
  • Hello Eugene,

    Using Copy and Paste am doing extraction, once object copied it will be present in Clipboard and from clipboard only it will get pasted, hope these things you will aware. I asked C#.Net and Excel forum they suggested me to ask in this forum. See i tried to execute that application by changing the platform to x64 but still it not working.

    Wednesday, March 26, 2014 4:32 AM
  • Hi,

    What do you mean by “Native”? As far as I test, I can get the data successfully from Excel add-in.
    Below is my steps:
    1. Create Excel add-in
    2. Add a ribbon(design) and insert a button
    3. Put the code below to the click event of button

    private void button1_Click(object sender, RibbonControlEventArgs e)
            {
                IDataObject iData = Clipboard.GetDataObject();
    
                if (iData != null)
                {
                    string name = iData.ToString();
                    //string objType = "Native";
                    object objToSave = iData.GetData("Text");
                    MessageBox.Show(objToSave.ToString());
    
                }
    
            }
    

    4. Open a notepad and write some words and copy it
    5. Run the Excel add-in and click the custom button on the ribbon

    I suggest you creating a common windows form application to test whether the code works.

    Best regards

    Fei


    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.

    Wednesday, April 2, 2014 9:48 AM
    Moderator
  • Hi Sathish,

    It looks like you forgot to answer my questions. Are you able to reproduce the issue with a regular standalone windows forms application? Just try to set the target platform to the x64 value. Does it work? Can you extract the object?

    Note, the Clipboard class doesn't belong to VSTO. It shouldn't depend on the target platform.

    Wednesday, April 2, 2014 1:54 PM
  • Hi Eugene,

    Yes i changed the target platform to x64 and i executed my application but still  it fails to extract the data. I didn't forgot answer you because in my previous reply of last line i mentioned by changing the target platform to x64 is not working.

    Wednesday, April 9, 2014 6:19 AM
  • Hi Fei,

    Thanks for your reply, actually "Native" is the DataFormat, you can able get the data which are not in the predefined DataFormats like(Text,MetaFile,Bitmap and etc). The Native format id 49156. The Code above will work fine for text, but our scenario is extract the embedded object(*.m) files present inside the excel file. I think while copying the object to clipboard the data gets lost.

    Wednesday, April 9, 2014 1:29 PM
  • Are you able to reproduce the issue with a regular standalone windows forms application (not an add-in)?

    Wednesday, April 9, 2014 2:05 PM
  • In windows form application only the issue been produced.
    Thursday, April 10, 2014 4:17 AM
  • Hi Sathish,

    > In windows form application only the issue been produced.

    Well, it confirms my assumptions that the issue is not related to VSTO at all. That's why I'd recommend asking such questions in the Visual C# forums - just post an issue with your windows forms application. The issue is common for all .Net based applications.

    Thursday, April 10, 2014 8:48 AM