[]
        
(Showing Draft Content)

TableSheet IO

You can export a TableSheet in various formats such as JSON, Excel, PDF, and even print it just like printing a spreadsheet.

JSON Serialization

TableSheet JSON serialization and deserialization are done using the workbook's toJSON and fromJSON methods.

function saveJSON() {
    // Save JSON
    var json = spread.toJSON({ includeBindingSource: true, saveAsView: true });
    saveAs(new Blob([JSON.stringify(json)], { type: "text/plain;charset=utf-8" }), 'exportedJSON.ssjson');
}

function openJSON() {
    // Load JSON
    var file = document.getElementById("fileDemo").files[0];
    if (file) {
        var reader = new FileReader();
        reader.onload = function () {
            var json = JSON.parse(this.result);
            spread.fromJSON(json);
        };
        reader.readAsText(file);
    }
}

Export Excel Files

Exporting tablesheet to Excel is done using the GC.Spread.Excel.IO save method. TableSheet is treated as a table in a worksheet and includes alternatingRowStyles and conditional format results when saveAsView is true and excludes icon set, data bar, and data validation.

It is necessary to set includeBindingSource to true when exporting to Excel. It is optional to set saveAsView to true when exporting to Excel.

function saveExcel() {
    // Save Excel
    var excelIo = new GC.Spread.Excel.IO();
    var json = spread.toJSON({ includeBindingSource: true, saveAsView: true });
    excelIo.save(json, function (blob) {
        saveAs(blob, "exportedExcel.xlsx");
    }, function (e) {
        console.log(e);
    });
}

Export PDF

Exporting tablesheet to PDF is done using the workbook's savePDF method. PDF includes binding results and excludes icons, options, and actionColumn.


For printing or exporting to PDF, users can customize the print information using the printInfo method.

function savePDF() {
    // Save PDF
    spread.savePDF(function (blob) {
        saveAs(blob, "exportedPDF.pdf");
    }, function (error) {
        console.log(error);
    }, null, spread.getSheetCount() + spread.getActiveSheetTabIndex());
}

TableSheet printing is done using the workbook's print method. Print includes binding results and excludes icons, options, and actionColumn.

function print() {
    // Print Spread
    spread.print();
}