Page tree
Skip to end of metadata
Go to start of metadata

你可以导入或者导出 JSON 格式的文件,后缀名为 .json。

早期版本的 Spread.Sheets 无法载入由 SpreadJS 3.20142.11导出的 JSON 文件

示例代码

以下例子演示了如何导入和导出 JSON 文件。

JavaScript
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]);

示例代码

以下 Visual Studio 的例子演示了如何导入 ssjson 文件。

Web.config
<?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>
HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <title>TestLoad ssjson</title>
    <!--Spread.Sheets Widgets CSS-->
    <link href="./css/gc.spread.sheets.10.x.x.css" rel="stylesheet" type="text/css" />
         
    <!--jQuery Reference-->
    <script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>            
    <!--Spread.Sheets Widgets JavaScript-->
    <script src="./scripts/gc.spread.sheets.all.10.x.x.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {                    
            var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
            $.ajax({
                url: "TestFile.ssjson",
                datatype: "json",
                success: function (data) {
                    //here to load ssjson file.
                    spread.suspendPaint();
                    spread.fromJSON(JSON.parse(data));
                    spread.resumePaint();
                },
                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>

更多信息

fromJSON Method
fromJSON Method


  • No labels