paste

Fired when a data is about to be pasted in a sheet.

Event Data

e.sender kendo.ui.Spreadsheet

The widget instance which fired the event.

e.range kendo.spreadsheet.Range

The Range that is currently selected in the spreadsheet. The actual selection will change according to the pasted range / values.

e.clipboardContent Object

The content that has been passed from the clipboard to the paste command. This data allows you to prevent the default execution of the paste functionality, manipulate the data and paste it properly in the widget content area.

Example - paste only values in the Spreadsheet

<div id="example">
    <div id="spreadsheet"></div>
</div>

<script>
    $("#spreadsheet").kendoSpreadsheet({
        sheets:[{
            name: 'test',
            rows: [{
                cells: [{
                    value: 12.39,
                    format: "$#,##0.00",
                    background: "rgb(255,255,255)",
                    color: "rgb(0,62,117)"
                }]
            }]
        }],
        paste: function(e) {
            e.preventDefault()

            var currentRange = e.range;
            var fullData = e.clipboardContent.data;
            var mergedCells = e.clipboardContent.mergedCells;
            var topLeft = currentRange.topLeft();
            var initialRow = topLeft.row;
            var initialCol = topLeft.col;
            var origRef = e.clipboardContent.origRef;
            var numberOfRows = origRef.bottomRight.row - origRef.topLeft.row + 1;
            var numberOfCols = origRef.bottomRight.col - origRef.topLeft.col + 1;
            var spread = e.sender;
            var sheet = spread.activeSheet();
            var rangeToPaste =  sheet.range(initialRow, initialCol, numberOfRows, numberOfCols);

            sheet.batch(function() {
                for(var i = 0; i < fullData.length; i += 1) {
                    var currentFullData = fullData[i];

                    for(var j = 0; j < currentFullData.length; j += 1 ) {
                        var range = sheet.range(initialRow + i, initialCol + j);
                        var value = currentFullData[j].value;

                        if (value !== null) {
                            range.input(value);
                            range.format(null);
                        }
                    }
                }
            });

            sheet.select(rangeToPaste);

            for(var i = 0; i < mergedCells.length; i += 1) {
                var initialMergedRange = sheet.range(mergedCells[i]);
                var mergeTopLeft = initialMergedRange.topLeft();
                var mergeInitialRow = mergeTopLeft.row + initialRow;
                var mergedInitialCol = mergeTopLeft.col + initialCol;
                var mergedNumberOfRows = initialMergedRange.values.length;
                var mergedNumberOfCols = initialMergedRange.values()[0].length;

                sheet.range(mergeInitialRow, mergedInitialCol, mergedNumberOfRows, mergedNumberOfCols).merge();
            }
        }
    });
</script>
e.preventDefault Function

If invoked the paste will not be performed and no new data / formatting will be populate on the sheet.

In this article
Not finding the help you need? Improve this article