Format to JSON

Hi,

I open an excel and I can see in the spreadsheet.


I have a button to export to JSON

    const jsonString = this.spreadsheetObj.sheets.map(sheet => ({
      name: sheet.name,
      rows: sheet.rows.map(row => ({
        cells: row.cells.map(cell => ({
          value: cell.value,
          formula: cell.formula,
        })),
      })),
    }));


But if I inject this json to spreadsheet doesn't works.

I would like after load an excel, get the data(mutliples sheets), transforms this data to copy in other ejs-spreadsheet


1 Reply

GS Gobalakrishnan S Syncfusion Team November 1, 2024 02:09 PM UTC

Hi Jose,

We have reviewed your query and understand that you wish to save and open data as a JSON object in our Spreadsheet component. This functionality can be achieved using the openFromJson and saveAsJson methods.

The saveAsJson method saves the entire Spreadsheet data as a JSON object, capturing all features used within the Spreadsheet. The openFromJson method loads this saved JSON data back into the Spreadsheet.

To demonstrate, we have prepared a sample that saves the Spreadsheet data as JSON using the saveAsJson method and then opens it with the openFromJson method upon a button click. For your reference, we have included the sample and a code snippet below.

    saveJson() {

        this.spreadsheetObj.saveAsJson().then((result) => {

            this.json = result;

            console.log(this.json);

        })

    }

    openJson() {

        this.spreadsheetObj.openFromJson({file: this.json.jsonObject});

    }


Sample link: Odusd3 (forked) - StackBlitz

For more information, please refer the below documentation,

https://ej2.syncfusion.com/angular/documentation/spreadsheet/open-save#configure-json-deserialization-options

https://ej2.syncfusion.com/angular/documentation/spreadsheet/open-save#configure-json-serialization-options


Kindly check the above shared details and get back to us if you need further clarifications.


Loader.
Up arrow icon