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

workbook.ToJson() with just content?

3 Answers 161 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
B
Top achievements
Rank 1
B asked on 25 May 2016, 04:14 PM

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!

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 27 May 2016, 01:58 PM

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!
 
0
RPI Bumper to Bumper Auto Parts
Top achievements
Rank 2
answered on 18 Jul 2019, 12:31 PM
Could you please show an example of the row, cell iteration.
0
Dimitar
Telerik team
answered on 22 Jul 2019, 08:22 AM
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.
Tags
Spreadsheet
Asked by
B
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
RPI Bumper to Bumper Auto Parts
Top achievements
Rank 2
Dimitar
Telerik team
Share this question
or