[]
        
(Showing Draft Content)

JSON 가져오기 및 내보내기

fromJSON 메서드toJSON 메서드를 사용하여 JSON 개체에서 데이터를 가져오거나 JSON 개체로 데이터를 내보낼 수 있습니다.

JSON 개체에서 데이터를 가져올 때 사용자 지정 데이터 가져오기를 위한 여러 역직렬화 옵션을 설정할 수 있습니다. 이러한 옵션에는 ignoreStyle, ignoreFormula, frozenColumnsAsRowHeaders, frozenRowsAsColumnHeadersdoNotRecalculateAfterLoad가 포함됩니다.

JSON 개체로 데이터를 내보낼 때 사용자 지정 데이터 내보내기를 위한 여러 직렬화 옵션을 설정할 수 있습니다. 이러한 옵션에는 includeBindingSource, ignoreStyle, ignoreFormula, saveAsView, rowHeadersAsFrozenColumns, columnHeadersAsFrozenRows, includeAutoMergedCells, saveR1C1FormulasaveExternalSourcePivotCache가 포함됩니다.

참고: 이전 버전의 SpreadJS에서는 SpreadJS 3.20142.11 이상에서 생성된 JSON 파일을 로드할 수 없습니다.

JSON 개체로 내보내기 및 JSON 개체에서 가져오기

다음 코드 샘플에서는 JSON 개체로 내보내고 JSON 개체에서 가져오는 방법을 보여줍니다.

workbook.fromJSON(jsonData, {
    ignoreFormula: true,
    ignoreStyle: true,
    frozenColumnsAsRowHeaders: false,
    frozenRowsAsColumnHeaders: false,
    doNotRecalculateAfterLoad: true
});
workbook.toJSON({
    includeBindingSource: true,
    ignoreFormula: true,
    ignoreStyle: true,
    saveAsView: true,
    rowHeadersAsFrozenColumns: true,
    columnHeadersAsFrozenRows: true,
    includeAutoMergedCells: true,
    saveR1C1Formula: true,
    saveExternalSourcePivotCache: true
});

외부 피벗 원본의 PivotCache 데이터 저장

데이터 매니저 테이블 또는 뷰와 같은 외부 피벗 원본에서 피벗 테이블을 생성한 경우 JSON 및 SJS 저장 작업에서는 피벗 원본 관계가 유지되므로 이후 피벗 테이블이 원본에 다시 연결하여 새로 고칠 수 있습니다.

saveExternalSourcePivotCache 옵션을 사용하여 외부 피벗 원본의 구체화된 PivotCache 데이터를 저장할지 여부를 제어할 수 있습니다.

  • saveExternalSourcePivotCachetrue로 설정하면 저장된 JSON 또는 SJS 파일에 외부 원본 피벗 테이블의 구체화된 PivotCache 레코드가 포함됩니다. 파일을 다시 열면 저장된 캐시 데이터에서 피벗 테이블을 복원할 수 있으며, 이후 새로 고침을 위해 저장된 피벗 원본 관계를 계속 사용할 수 있습니다.

  • saveExternalSourcePivotCachefalse로 설정하면 저장된 JSON 또는 SJS 파일에서 피벗 원본 관계는 유지되지만 구체화된 외부 원본 PivotCache 레코드는 제외됩니다. 이렇게 하면 파일 크기를 줄일 수 있지만 데이터 매니저 데이터를 사용할 수 있게 된 후 데이터 매니저 테이블 또는 뷰에서 PivotCache를 다시 빌드해야 합니다.

workbook.toJSON({
    includeBindingSource: true,
    saveExternalSourcePivotCache: true
});

saveExternalSourcePivotCache 옵션은 워크북 저장 또는 내보내기 옵션입니다. 피벗 테이블 원본 속성이 아니며 피벗 테이블 원본을 변경하지 않습니다.

saveExternalSourcePivotCache의 기본값은 확인이 필요합니다.

ssjson 파일 로드

다음 샘플에서는 ssjson 파일을 로드합니다.

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

    <!--SpreadJS Widgets JavaScript-->
    <script src="./scripts/gc.spread.sheets.all.x.x.x.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        document.addEventListener("DOMContentLoaded", function () {
            var spread = new GC.Spread.Sheets.Workbook(
                document.getElementById("ss"),
                { sheetCount: 3 }
            );

            fetch("TestFile.ssjson")
                .then(function (response) {
                    if (!response.ok) {
                        throw new Error(response.status + " " + response.statusText);
                    }
                    return response.text();
                })
                .then(function (data) {
                    //here to load ssjson file.
                    spread.suspendPaint();
                    spread.fromJSON(JSON.parse(data));
                    spread.resumePaint();
                })
                .catch(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>