This is a migrated thread and some comments may be shown as answers.

Paste value without overriding initial formatting

2 Answers 312 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
iFACTS Admin
Top achievements
Rank 1
iFACTS Admin asked on 26 Oct 2017, 08:33 AM

Hi! I am getting close to having a great interface based on kendo spreadsheet. It's a really good control to work with, congrats to the team for doing such great work!

An issue I am having is that if I copy a value from external source (excel/etc) and pasting it in the spreadsheet, I lose the initial formatting. Any way to prevent that?

For example,in this demo https://demos.telerik.com/kendo-ui/spreadsheet/index, if I copy a quantity value and paste it on price, I lose formatting, which I planned to keep. Any ways around that?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Marc
Top achievements
Rank 1
answered on 27 Oct 2017, 07:17 AM

kendo.spreadsheet.Clipboard.prototype.paste = function () {
var sheet = this.workbook.activeSheet();
var pasteRef = this.pasteRef();
var content = this._content;

var currBackground = sheet.range(pasteRef).background();
var currColor = sheet.range(pasteRef).color();
var currFontSize = sheet.range(pasteRef).fontSize();
var currFontFamily = sheet.range(pasteRef).fontFamily();
var currTextAlign = sheet.range(pasteRef).textAlign();

var currEnable = sheet.range(pasteRef).enable();
var currItalic = sheet.range(pasteRef).italic();

sheet.range(pasteRef).setState(content, this);
sheet.triggerChange({ recalc: true, ref: pasteRef });

sheet.range(pasteRef)
.background(currBackground)
.color(currColor)
.bold(true)
.enable(currEnable)
.italic(currItalic)
.fontSize(currFontSize)
.fontFamily(currFontFamily)
.textAlign(currTextAlign);
};

 

 

This works for me, to keep colour, background etc so should work for formatting. Just override the paste prototype method, pull the formatting you have, and apply it after the paste.

0
Veselin Tsvetanov
Telerik team
answered on 30 Oct 2017, 08:58 AM
Hello Peter,

Currently, the Spreadsheet does not allow to keep the target formatting options on paste. Nevertheless, as Marc has suggested, the override of the kendo.spreadsheet.Clipboard.prototype.paste() method would allow you to alter this behavior of the widget in most cases.

Here you will find a small sample which demonstrates how the above suggestion would handle to cell formatting too. Keep in mind however, that this would not cover all scenarios. For example, it won't behave as expected, when pasting text values on cells with number formatting.

Note also, that the discussed functionality has already been requested on our Feedback portal. Therefore, I would suggest you to cast your vote for this feature request.

Regards,
Veselin Tsvetanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Spreadsheet
Asked by
iFACTS Admin
Top achievements
Rank 1
Answers by
Marc
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Share this question
or