Spreadsheet - Copy and paste function using API

1 Answer 16 Views
Spreadsheet
Brian
Top achievements
Rank 1
Iron
Brian asked on 17 Mar 2022, 06:28 AM

Hi,

How do i trigger a copy and paste function in kendo ui jquery spreadsheet via API? I am trying to copy a selected range of records and paste it over but it does not work with the below codes.

var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
var sheet = spreadsheet.activeSheet();

sheet.range(1, 0, 1, 100).select();
spreadsheet.trigger("copy");
sheet.range(0, 0, 1, 100).select();
spreadsheet.trigger("paste");

Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 21 Mar 2022, 01:05 PM

Hi Brian,

If you need to get the values in a specific range in Spreadsheet and set them as values in another range I would suggest you use the Range values() method.

function pasteValues(){
  var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
  var sheet = spreadsheet.activeSheet();
  var current = sheet.range("A1:B2").select();
  var values = current.values()    
  sheet.range("D1:E2").values(values);
}

Here is a Dojo example where this si demonstrated.

The trigger() method is supposed to be used to execute all attached event handlers. However, it will not invoke any methods, i.e.  it will not copy or paste data. 

Let me know in case you have additional questions on the matter.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Brian
Top achievements
Rank 1
Iron
commented on 22 Mar 2022, 12:54 AM

Hi,

Besides copy of values, i would like to copy the formula and format if any. Will your above solutions fulfil my requirements as well?

Neli
Telerik team
commented on 24 Mar 2022, 11:22 AM

Hi Brian,

The formula configured in a single cell can be retrieved and then set in another cell using the Range formula method:

https://docs.telerik.com/kendo-ui/api/javascript/spreadsheet/range/methods/formula

However, you will need to iterate over each cell in the copied range and get its formula.

Regards,

Neli

Tags
Spreadsheet
Asked by
Brian
Top achievements
Rank 1
Iron
Answers by
Neli
Telerik team
Share this question
or