Hi,
Is there anyway to overwrite the default value of the copy / paste functionality so that when a user copies a range and pastes it, the copy range formatting is not copied? (ie, copy value only)
Or is there some event I can intercept and use to do this?
Thanks
Marc
13 Answers, 1 is accepted
Currently there is no configuration option that allows to enable/disable pasting cells with/without formatting. We are considering the implementation of such in a future release. A possible workaround exists and consists of overwriting the paste function of the prototype as shown in this dojo example.
Regards,
Ivan Danchev
Progress Telerik
Hi Ivan!
This is great, thanks so much!
Hi Ivan
In the example dojo, the formatting is copied. Can you update it so that the formatting it not copied and only the data is copied over?
Thanks!
We do not have a different workaround for that missing feature, but the one I linked works as expected at my end. Here's a short screencast showing only the data being pasted, while formatting (the cells background color for instance) not being pasted.
Regards,
Ivan Danchev
Progress Telerik
Hi Ivan,
It works in your example yes, but if you copy that onto a cell that is already formatted then it will remove the formatting that is currently there.
This is the behaviour I'm looking for - ie, a ctrl+c - ctrl+v only copies the cell value.
Thanks!
Currently there isn't a reliable approach available that would prevent the formatting removal in the pasted cell. It could be done manually by setting the previous format to the cell after the content is pasted, but that would require calling multiple methods of the Range object for setting different formatting options (bold, textAlign, background, color, etc.). Here's an example which shows this with just two of the methods (background and textAlign):
var
background = sheet.range(pasteRef).background();
var
textAlign = sheet.range(pasteRef).textAlign();
sheet.range(pasteRef).background(background)
sheet.range(pasteRef).textAlign(textAlign);
Copy a cell's content from a column and paste it in a cell in another column: the original background and text alignment are persisted in the pasted cell.
Regards,
Ivan Danchev
Progress Telerik
Hi Ivan,
This is great thanks!
Just an FYI - you can chain the calls like so (to avoid multiple references to the range):
sheet.range(pasteRef)
.background(background)
.textAlign(textAlign);
We are glad the suggested approach worked out. We are aware of the methods chaining option, which would be reasonable to use, especially if there are calls to multiple methods.
Regards,
Ivan Danchev
Progress Telerik
Hi Ivan,
Thanks again - impressed as always with the support I get here1
Marc
http://dojo.telerik.com/eLUxIgEN
The previously suggested workaround depended on logic that has changed in the last release along with the multiple Spreadsheet bug fixes included in this release (release history notes). An implementation of an option to choose whether only the value or value + formatting will be pasted, would remove the need for workarounds consisting of overriding the source code. It would ensure that subsequent changes (e.g. bug fixes) would not affect this functionality. Therefore we would suggest voting for the respective feature request in our Feedback Portal.
Regards,
Ivan Danchev
Progress Telerik
Currently a workaround for the latest official version is not available. If we manage to come up with one we will post it both here and in the linked feature request in the Portal.
Regards,
Ivan Danchev
Progress Telerik