workbook.ToJson() with just content?

4 posts, 0 answers
  1. B
    B avatar
    25 posts
    Member since:
    Aug 2010

    Posted 25 May 2016 Link to this post

    Is it possible to retrieve just the cell contents (not formatting, etc) for a specific worksheet?  

    We're looking at a use case where we want to use a spreadsheet for loading a mongodb collection and don't care about all the formatting / metadata that seems to be there when you use ToJson.

    Thanks!

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 27 May 2016 Link to this post

    Hello B,

    There is no predefined method to extract just the content of the cell without the options. My suggestion is to iterate through the cells for each row in the sheet ( in the object returned by toJSON method) and remove formatting and etc options. 

    Regards,
    Boyan Dimitrov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. RPI Bumper to Bumper Auto Parts
    RPI Bumper to Bumper Auto Parts avatar
    2 posts
    Member since:
    Apr 2012

    Posted 18 Jul 2019 in reply to Boyan Dimitrov Link to this post

    Could you please show an example of the row, cell iteration.
  4. Dimitar
    Admin
    Dimitar avatar
    796 posts

    Posted 22 Jul 2019 Link to this post

    Hello,

    The results from the toJSON() method could be iterated as follows:
    var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
    var sheet = spreadsheet.activeSheet();
    var data = sheet.toJSON();
           
    var formattedRows = [];
    for (var i = 0; i < data.rows.length; i += 1) {
      var rowCells = data.rows[i].cells;
      var formattedCells = [];
               
      for (var j = 0; j < rowCells.length; j += 1) {         
        formattedCells.push({  index: rowCells[j].index, value: rowCells[j].value });
      }
               
      formattedRows.push({ index: data.rows[i].index, cells: formattedCells });
    }
           
    console.log(formattedRows);

    Here is a Dojo example where the above approach is demonstrated.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top