Spread.Services Documentation
Import and Export JSON Stream
Spread.Services Documentation > Developer's Guide > Manage Data in Spread Component > Import and Export JSON Stream

The sole purpose of facilitating users in importing and exporting to and from json stream is to enable them to exchange and organize object data as and when required. This reference summarizes how Spread.Services handles the import and export of json stream using .Net core.

You can export a workbook to a json string/stream using the ToJson method of the IWorkbook interface. You can also import a json string or stream to your workbook using the FromJson method of the IWorkbook interface.

Refer to the following example code to import and export json stream.

C#
Copy Code
//ToJson&FromJson can be used in combination with spread.sheets product

//spread.services import an excel file.
//change the path to real source file path.
string source = "savingfile.xlsx";
workbook.Open(source);

//spread.services export to a json string.
var jsonstr = workbook.ToJson();
//use the json string to initialize spread.sheets product.
//spread.sheets will show the excel file contents.

//spread.sheets product export a json string.
//spread.services use the json string to initialize.
workbook.FromJson(jsonstr);
//spread.services export workbook to an excel file.
//change the path to real export file path.

string export = "export.xlsx";
workbook.Save(export);

SpreadJS SSJSON Support

Spread.Services provides support for SpreadJS 11 SSJSON. You can import a SSJSON file created with Spread.Sheets Designer and save it back after modifying it as per your preferences.

C#
Copy Code
//Create a new workbook
Workbook workbook = new Workbook();                      
            
//Load SSJSON file 
var stream = new System.IO.FileStream("Chart_Spread.ssjson", System.IO.FileMode.Open);
workbook.FromJson(stream);
            
//Save file 
workbook.Save("workbook_ssjson.xlsx");