SpreadJS 13
GC.Spread.Excel Namespace / IO type / save Method
The spread sheets json object, or string.
Call this function after successfully exporting the file. function (blob) { }.
Call this function if an error occurs. The exception parameter object structure { errorCode: GC.Spread.Excel.IO.ErrorCode, errorMessage: string}.
The options for export excel.
the excel file's password.
In This Topic
    save Method
    In This Topic
    Creates and saves an excel file with the SpreadJS json.
    Syntax
    var instance = new GC.Spread.Excel.IO();
    instance.save(json, successCallBack, errorCallBack, options, options.password);
    function save( 
       json : object,
       successCallBack : function,
       (optional) errorCallBack : function,
       (optional) options : Object,
       (optional) options.password : string
    ) : void;

    Parameters

    json
    The spread sheets json object, or string.
    successCallBack
    Call this function after successfully exporting the file. function (blob) { }.
    errorCallBack
    Call this function if an error occurs. The exception parameter object structure { errorCode: GC.Spread.Excel.IO.ErrorCode, errorMessage: string}.
    options
    The options for export excel.
    options.password
    the excel file's password.
    Example
    This example opens and saves files. Use the browse button to find an Excel file to import. Then select Import to import a file.
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>SpreadJS V11 Client Side ExcelIO</title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2014-11-29/FileSaver.min.js"></script>
        <link href="./css/gc.spread.sheets.excel2013white.12.0.0.css" rel="stylesheet"/>
        <script src="./scripts/gc.spread.sheets.all.12.0.0.min.js" type="application/javascript"></script>
        <!--For client-side excel i/o-->
        <script src="./scripts/interop/gc.spread.excelio.12.0.0.min.js"></script>
    </head>
    <body>
    <div>
        <input type="file" name="files[]" id="fileDemo" accept=".xlsx"/>
        <input type="button" id="loadExcel" value="Import" onclick="ImportFile()"/>    
        <input type="button" class="btn btn-default" id="saveExcel" value="Export" onclick="ExportFile()"/>
    <input type="text" id="exportFileName" placeholder="Export file name" class="form-control" value="export.xlsx"/>
        <div id="ss" style="width:100%;height:500px"></div>
    </div>
    </div>
    </body>
    <script>
    var workbook, excelIO;
    window.onload = function () {
    workbook = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
    excelIO = new GC.Spread.Excel.IO();
        }
    
        function ImportFile() {
            var excelFile = document.getElementById("fileDemo").files[0];
            excelIO.open(excelFile, function (json) {
                var workbookObj = json;
               workbook.fromJSON(workbookObj);
            }, function (e) {
                console.log(e);
            });
        }
    
        function ExportFile() {
            var fileName = document.getElementById("exportFileName").value;
            if (fileName.substr(-5, 5) !== '.xlsx') {
                fileName += '.xlsx';
            }
            var json = JSON.stringify(workbook.toJSON());
            excelIO.save(json, function (blob) {
                saveAs(blob, fileName);
            }, function (e) {
                console.log(e);
            });
        }
    </script>
    </html>
    See Also

    Reference

    IO type