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

import excel sheet data to row x (i.e. A2)

1 Answer 267 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Morten
Top achievements
Rank 2
Iron
Iron
Veteran
Morten asked on 08 Apr 2021, 06:59 AM

I have a sheet with a header column, that I would like to preserve during an import of an Excel file.

In a kendoUpload.success event I import the uploaded Excel file like this: $spreadsheet.fromJSON(e.response);

Is there a clever way to have e.response inserted into the second column starting at cell A2?

/Morten

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 13 Apr 2021, 05:32 AM

Hello Morten,

The Spreadsheet fromJSON() method resets all the sheet data, thus when using this method the header must also be part of the constructed data that is passed to it:

Alternatively, you can try using the Sheet fromJSON() method specify that can merge the configuration and cell values. In this way the row index can specify where data will be inserted as follows:

 var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
  var sheet = spreadsheet.sheetByIndex(0);
  sheet.fromJSON({
    rows: [{
      index: 2,
      cells: [{
        value: "Calzone"
      }, {
        value: 1
      }, {
        value: 12.29, format: "$#,##0.00"
      }]
    }, {
      index: 3,
      cells: [{
        value: "Margarita"
      }, {
        value: 2
      }, {
        value: 9.11, format: "$#,##0.00"
      }]
    }]
  });

You can review the following example where there is a header set initially in the Spreadsheet. Then, through the fromJSON() method we inject just the table data:

However, please note that this approach has some limitations in terms of the data being loaded -  the JSON should not contain more rows or columns than defined when the Spreadsheet object has been constructed, as with this method the Sheet object is not resizable.

I hope this helps.

Regards,
Dimitar
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/.

Tags
Spreadsheet
Asked by
Morten
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Dimitar
Telerik team
Share this question
or