# TableSheet IO

## Content

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

## JSON Serialization

<span style="color: rgb(0, 0, 0); font-family: 游ゴシック; font-size: 14.6667px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">TableSheet JSON serialization and deserialization are done using the workbook's toJSON and fromJSON methods.</span>

```javascript
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](/spreadjs/api/v16/classes/GC.Spread.Sheets.Workbook#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.

```javascript
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](/spreadjs/api/v16/classes/GC.Spread.Sheets.Workbook#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](/spreadjs/api/v16/classes/GC.Spread.Sheets.Print.PrintInfo) method.

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

## Print Tablesheet

TableSheet printing is done using the workbook's [print](/spreadjs/api/v16/classes/GC.Spread.Sheets.Workbook#print) method. Print includes binding results and excludes icons, options, and actionColumn.

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