Copy selected cells to clipboard

Posted by: kd-bc on 8 September 2017, 12:53 pm EST

  • Posted 8 September 2017, 12:53 pm EST

    How do copy the currently selected cells (more than 1) to the clipboard?


    Thanks!


     

  • Replied 8 September 2017, 12:53 pm EST

    It won't copy the entire sheet.  It will only copy the contents of the active cell or the contents of the selection you have made.
  • Replied 8 September 2017, 12:53 pm EST

    I don't want to copy the whole sheet, I just want to copy the active cells.
  • Replied 8 September 2017, 12:53 pm EST

    You only use an InputMap if you want to change the default keys that would normally do a copy(CTRL-C).  As I said, you can either do a CTRL-C from the keyboard or FpSpread1.ActiveSheet.ClipboardCopy()
  • Replied 8 September 2017, 12:53 pm EST

    Thanks, but how exactly do I do that? 


    the help example:


    Dim im As FarPoint.Win.Spread.InputMap
    im = FpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused)
    im.Put(New FarPoint.Win.Spread.Keystroke(Keys.P, Keys.None), FarPoint.Win.Spread.SpreadActions.ClipboardCopy)

     

    really isn't a whole lot of help.
  • Replied 8 September 2017, 12:53 pm EST

    You can either do a CTRL-C or call the sheets ClipboardCopy method.
  • Replied 8 September 2017, 12:53 pm EST

    I have a related question and figured I'd tag it on here: I notice that ClipboardCopy differentiates between multiple rows with \r\n characters. This is somewhat problematic in case I am handling a paste operation from the clipboard where the text of 1 cell may legitimitely have \r\n characters (such as the text of a multiline rich edit control). How can I (and related - how can I force ClipboardPaste to) differentiate between multiple row values in the clipboard vs legit \r\n chars?


     

  • Replied 8 September 2017, 12:53 pm EST

    Bill -

    The paste should take into account the carriage returns and line feeds from a multiline cell.  Are you having issues with this?  Here are a few posts that explain the Clipboard.GetDataObject...

    http://www.clubfarpoint.com/Forums/forums/post/11555.aspx

    http://www.clubfarpoint.com/Forums/forums/post/52899.aspx

    The ClipboardPaste method has two overrides that take the IDataObject as one of its parameters.


  • Replied 8 September 2017, 12:53 pm EST

    Bill -

    On the clipboard all the information for one cell would be in quotes.  You would have to parse the text on the clipboard and add those quotes around Hi and There so it would be pasted into one cell.  Here's a link that shows how to get the data off the clipboard...

    http://www.clubfarpoint.com/Forums/forums/thread/37429.aspx


  • Replied 8 September 2017, 12:53 pm EST

    Bill -

    That is the expected behavior and is the way the clipboard works.  The clipboard inserts the \r\n.  What would you expect to have happen when you paste the data into spread?
  • Replied 8 September 2017, 12:53 pm EST

    That's a good question Bob. I noticed that Excel uses \r\n as well when pasting in multiple cells and I would expect multiple rows to be updated in that case. But there is a case where our users expect only the 1 cell being pasted into to be updated and become multiline. So instead of two cells, one with Hi, and one with There, the cell being pasted into would contain


    Hi


    There


     

  • Replied 8 September 2017, 12:53 pm EST

    Thanks for the info Bob.


     


    The issue I am running into is follows:


     


    I type:


     Hi


    There


    into Notepad so that hi and there are on separate lines. I then copy this text to the clipboard and then paste into a cell in FarPoint. I get Hi on the cell I selected to paste into, and There on the cell at the same column, next row down. Note I am using FarPoint v1, not the latest and greatest yet. It appears that the ClipboardPaste is assuming that \r\n is a row delimiter. Does this make sense?


     

  • Replied 8 September 2017, 12:53 pm EST

    Here is what I'm seeing:


    Scenario A:


    2 cells in FarPoint, column A, rows 1 and 2. A1 = Hello, A2=There. I select both cells and do a ClipboardCopy. My clipboard data is set to


      "Hello\r\nThere\r\n"


    Scenario B:


    I have


    Hello


    There


    in Notepad. I select the text and copy into the clipboard. My clipboard data is set to


    "Hello\r\nThere\r\n"


     


    My problem is that at paste time, with that string, I have no way of knowing whether the text is meant to go into 1 cell or 2. Am I missing something? The strings are identical. But the intent is not. In Scenario A, the intent is two paste 2 cell values into 2 other cells. In Scenario B, the intent is to paste 1 value into 1 cell.



     

  • Replied 8 September 2017, 12:53 pm EST

    Thanks Scott and Bob, for your help. I noticed that Pasting from a multiline cell from Excel 2007 yields:


    "\"Hello\nWorld\"\r\n"


     


    I will parse the data accordingly. Thanks again.


     

  • Replied 8 September 2017, 12:53 pm EST

    Hello,


    To get data with the delimiters in the cell, you would need to delimit the cell data with quotation marks ("). The string """Hello\r\nWorld""" when pasted into Spread will paste into one cell. If multiline is turned on for the cell being pasted, then you will see the string paste correctly on multiple lines in one cell. The string you are using "Hello\r\nWorld" will always paste into two different cells as you ar eseeing.

  • Replied 8 September 2017, 12:53 pm EST

    There is no way to know.  You would have to get the data off the clipboard then parse it to strip out the first \r\n so it would go into one cell.
Need extra support?

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

Learn More

Forum Channels