Paste value without overriding initial formatting

3 posts, 0 answers
  1. Peter
    Peter avatar
    7 posts
    Member since:
    Feb 2017

    Posted 26 Oct Link to this post

    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. Marc
    Marc avatar
    167 posts
    Member since:
    Sep 2016

    Posted 27 Oct Link to this post

    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.

  3. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    612 posts

    Posted 30 Oct Link to this post

    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.
Back to Top