ClipboardCopy

Posted by: quim on 8 September 2017, 3:05 pm EST

  • Posted 8 September 2017, 3:05 pm EST

    Hi

     

    I'm copying a range of cells in order to paste all the cell formats to new cells that are inserted in a loop.

    The code is executed always in the same way (it's a report that is build always with same data). The problem is that sometimes I get this error when using "ClipboardCopy":

    <b> "Requested Clipboard operation did not succeed" </b>

     

    this is the code I'm using

     

    with sp1.sheets(0)

                    .AddSelection(row1, col1, 1, last_col - col1 + 1)

                    crange = fp.ActiveSheet.GetSelection(0)

                    .ClipboardCopy(crange, Spread.ClipboardCopyOptions.All)


                    .ClearSelection()

                    While rd.Read

                             ...

                           .SetActiveCell(r, col1)
                            .ClipboardPaste(Spread.ClipboardPasteOptions.All)

                              ...

                     end While

    end with

     

    Should I create a kind of loop to wait and retry several times?

     

    Regards

  • Replied 8 September 2017, 3:05 pm EST

    Hello,

    There is no such issue reported in the past or any known issue related to ClipboardCopy, so it would be difficult to comment on the issue without replicating the same at my end. I would request you to provide a sample application depicting your issue so that I can replicate the issue at my end and debug it further.

    However there are several links that suggest to try the copy paste operation several times to resolve the issue, here are a few links:

              http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/31da5cec-7d47-41f0-a2e5-ee16e609a871

              http://stackoverflow.com/questions/5707990/requested-clipboard-operation-did-not-succeed

    You may try implementing the same. Hope it helps.

    Thanks,

    Manpreet Kaur

  • Replied 8 September 2017, 3:05 pm EST

    Hi

     This makes all the sense, but it's also a problem because if the application makes a copy to clipboard and is doing a paste inside a loop the clipboard content may change during the loop if any other application uses the clipboard.

    It's the same as using a global memory variable that can be written by any windows application.

    Do I have any other way to copy the formats of a specific cell range where I don't know what to expect (may be different borders, fonts names or sizes, alignment, background and foreground color, cell types, etc) and apply those formats to a new range of cells?

     

    Regards

  • Replied 8 September 2017, 3:05 pm EST

    Hello,

    There seems to be no other way to copy paste the formatting of a cell range. You would need to use the copy paste operations i.e the ClipboardCopy and ClipboardPaste methods to accomplish the same.

    Thanks,

    Manpreet  Kaur

  • Marked as Answer

    Replied 29 September 2017, 12:57 pm EST

    Hi quim,

    Try this code, I just have same problem and fixed. You can refer to another thread was talking about this error message and may have help. https://www.grapecity.com/en/forums/spread-winforms/clipboard-corruption

    DataObject o = new DataObject();
    o = sdPrint.GetClipDataObject(false, new CellRange(0, 0, 5, 5), ClipboardCopyOptions.All);
    sdPrint.SetActiveCell(20, 10);
    sdPrint.ClipboardPaste(ClipboardPasteOptions.All);
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels