SpreadJS Documentation
Importing and Exporting to JSON

You can import or export data to JSON objects or files (JavaScript Object Notation). The JSON filename extension is .json.

Earlier versions of SpreadJS cannot load JSON files created with SpreadJS 3.20142.11 or later.

Using Code

This example exports to and imports from a JSON object.

JavaScript
Copy Code
activeSheet.getCell(0,0).value(123);
var jsonStr = null;
//export
jsonStr = JSON.stringify(spread.toJSON());
//import
spread.fromJSON(JSON.parse(jsonStr));
alert(jsonStr);
//alert(jsonStr[0]);

Using Code

This Visual Studio example loads an ssjson file.

Web.config
Copy Code
<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, visit http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".ssjson" mimeType="text/plain" />
    </staticContent>
  </system.webServer>
</configuration>
JavaScript
Copy Code

<!DOCTYPE html>
<html lang="en">
<head>
    <title>TestLoad ssjson</title>
    <!--SpreadJS Widgets CSS-->
    <link href="./css/gcspread.sheets.9.40.20153.0.css" rel="stylesheet" type="text/css" />
         

    <!--jQuery Reference-->
    <script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>            

    <!--SpreadJS Widgets JavaScript-->
    <script src="./scripts/gcspread.sheets.all.9.40.20153.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {                    
            var spread = new GcSpread.Sheets.Spread($("#ss").get(0),{sheetCount:3});
            $.ajax({
                url: "TestFile.ssjson",
                datatype: "json",
                success: function (data) {
                    //here to load ssjson file.
                    spread.isPaintSuspended(true);
                    spread.fromJSON(JSON.parse(data));
                    spread.isPaintSuspended(false);
                },
                error: function (ex) {
                    alert('Exception:' + ex);
                }
            });
        });
    </script>
</head>

<body>

    <div class="container">
        <div class="header">
            <h2>Sample for load .ssjson file</h2>
        </div>
        <div id="ss" style="width: 100%; height: 430px; border: 1px solid gray;"></div>
    </div>
</body>

</html>

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Send comments on this topic.